I know I can do this
glob('/dir/somewhere/*.zip');
but is there a way to return all files that are not ZIPs?
Or should I just iterate through and filter off ones with that extension?
Thanks
I know I can do this
glob('/dir/somewhere/*.zip');
but is there a way to return all files that are not ZIPs?
Or should I just iterate through and filter off ones with that extension?
Thanks
I don't think glob can do a "not-wildcard"...
I see at least two other solutions :
opendir
/ readdir
/ closedirDirectoryIterator
; and maybe you can combine it with some FilterIterator
?You could always try something like this:
$all = glob('/dir/somewhere/*.*');
$zip = glob('/dir/somewhere/*.zip');
$remaining = array_diff($all, $zip);
Although, using one of the other methods Pascal mentioned might be more efficient.
Just had a thought... this would only ever be ideal if I knew there would only be say 3 file types in a folder.
So say I knew we had JPG, GIF and ZIP only in that folder ever. I could do
$images = glob($imagesDir . '*.{jpg,gif}', GLOB_BRACE);
That would effectively get me all files that are not ZIP. However, in practise, other files could show up in that directory and throw this out.
I would say this is not ideal - but I'm posting it anyway as another viewpoint.