Does glob() have negation?

alex picture alex · Dec 10, 2009 · Viewed 8.9k times · Source

I know I can do this...

glob('/dir/somewhere/*.zip');

...to get all files ending in .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?

Answer

Atli picture Atli · Dec 10, 2009

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.