tags:

views:

171

answers:

4

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

+3  A: 

I don't think glob can do a "not-wildcard"...

I see at least two other solutions :

Pascal MARTIN
+3  A: 

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.

Atli
This method is more elegant. +1
Alix Axel
A: 

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.

alex
A: 
$dir = "/path";
if (is_dir($dir)) {
    if ($d = opendir($dir)) {
           while (($file = readdir($d)) !== false) {
                if ( substr($file, -3, 3) != "zip" ){
                    echo "filename: $file \n";
                }
           }
        closedir($d);
    }
}

NB: "." and ".." not taken care of. Left for OP to complete