问题
I have a bunch of folders with these file types spread across them .mp4,.flv,.wmv,.mov
/video/o/y/oyr800/clips/1.flv
/video/p/y/pyr800/clips/1.wmv
/video/q/y/qyr800/clips/1.mp4
/video/51/51.mov
/video/52/52.flv
I tried using this function to list the paths and filenames but it gives me a blank return:
print_r(rglob('{*.mp4,*.flv,*.wmv,*.mov}',GLOBAL_BRACE));
function rglob($pattern, $flags = 0) {
$files = glob($pattern, $flags);
foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir) {
$files = array_merge($files, rglob($dir.'/'.basename($pattern), $flags));
}
return $files;
}
Not sure what is wrong.
回答1:
Ended up using this:
print_r(rsearch("C:\wamp\www","/^.*\.(mp4|flv|wmv|mov)$/"));
function rsearch($folder, $pattern) {
$dir = new RecursiveDirectoryIterator($folder);
$ite = new RecursiveIteratorIterator($dir);
$files = new RegexIterator($ite, $pattern, RegexIterator::GET_MATCH);
$fileList = array();
foreach($files as $file) {
$fileList[] = $file[0];
}
return $fileList;
}
Works great!
回答2:
Check out this post for example:
http://thephpeffect.com/recursive-glob-vs-recursive-directory-iterator/
Might want to look at the Recursive Directory Iterator as well
来源:https://stackoverflow.com/questions/25257717/php-recursive-directory-search-using-glob-for-multiple-file-types