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.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With