Skip to content

Instantly share code, notes, and snippets.

@adampatterson
Created October 26, 2012 20:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adampatterson/3961278 to your computer and use it in GitHub Desktop.
Save adampatterson/3961278 to your computer and use it in GitHub Desktop.
recursive_glob
/**
* Function: recursive_glob
* Recursively goes through a folder and returns all files.
*
* Parameters:
* $pattern - String
* $flags - Boolean
* $path - String
*
* Returns:
* $files - Array
*/
function recursive_glob($pattern='*', $flags = 0, $path='')
{
$paths = glob($path.'*', GLOB_MARK|GLOB_ONLYDIR|GLOB_NOSORT);
$files = glob($path.$pattern, $flags);
foreach ($paths as $path) {
$files=array_merge($files,recursive_glob($pattern, $flags, $path));
}
return $files;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment