In data2
directory, I have these files:
With the following code (running on Mac), I want to only get the files that end with .xls
:
$file_names = glob('data2/*.xls');
foreach ($file_names as $file_name) {
echo $file_name . '<br/>';
}
I would expect that this code would return one file 27template.xls
, however, it also returns the files with TEMP
in them and adds a .xls
to them:
Added: also if I change smaller.xls
to smaller.xlsx
then it does NOT find it as expected, but if I change it to smaller.NNN
it finds smaller.NNN.xls
.
How can I use glob()
to only get .xls
files?
I think it is because the extension you are looking at might be not the real one (hided by default on Finder). You can check the real extension by clicking on the file and click on "Get info". If you want to show the extensions of all file you have to follow the steps by the Apple documentation:
To show the extension for all files, choose Finder > Preferences and click Advanced, then select "Show all file extensions."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With