我现在有这个代码:
//path to directory to scan
$directory = "./";
//get all image files with a .m4v/.mp4 extension.
$images = glob($directory . "*.{m4v,mp4,mkv}", GLOB_BRACE);
将此转换为递归搜索相同文件类型的任何子目录的最快方法是什么?
答案 0 :(得分:0)
$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator('.'));
$images = array();
foreach ($objects as $name => $object)
{
/* @var $object SplFileInfo */
if (in_array($object->getExtension(), array('m4v', 'mp4', 'mkv')))
$images[] = $name;
}
答案 1 :(得分:0)
function RecursiveGetfiles($dir)
{
$files=array();
foreach(glob('$dir/*') as $d)
{
if(is_dir($d))
{
$files[]=RecursiveGetfiles($d);
}
}
$files=glob($directory . "*.{m4v,mp4,mkv}", GLOB_BRACE);
return $files;
}