我有一堆文件夹,这些文件类型分布在 .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
我尝试使用此函数列出路径和文件名,但它给我一个空白的回报:
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;
}
不确定是什么问题。
答案 0 :(得分:1)
结束使用:
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;
}
效果很好!
答案 1 :(得分:0)
查看此帖子,例如:
http://thephpeffect.com/recursive-glob-vs-recursive-directory-iterator/
也可以查看Recursive Directory Iterator