Does glob() have negation?

前端 未结 5 1765
执念已碎
执念已碎 2020-12-10 13:47

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 f

5条回答
  •  無奈伤痛
    2020-12-10 14:04

    $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

提交回复
热议问题