Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Recursive glob search in php
/*
* License: DWTFYW
*/
function glob_recursive($base, $pattern, $flags = 0) {
if (substr($base, -1) !== DIRECTORY_SEPARATOR) {
$base .= DIRECTORY_SEPARATOR;
}
$files = glob($base.$pattern, $flags);
foreach (glob($base.'*', GLOB_ONLYDIR|GLOB_NOSORT|GLOB_MARK) as $dir) {
$dirFiles = glob_recursive($dir, $pattern, $flags);
if ($dirFiles !== false) {
$files = array_merge($files, $dirFiles);
}
}
return $files;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.