Created
December 28, 2013 18:00
-
-
Save nhaskins/8162175 to your computer and use it in GitHub Desktop.
#php directory recursive search for files by an extension, return as array.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// $Id: rglob.php,v 1.0 2008/11/24 17:20:00 hm2k Exp $ | |
/** | |
* Recursive glob() | |
*/ | |
/** | |
* @param int $pattern | |
* the pattern passed to glob() | |
* @param int $flags | |
* the flags passed to glob() | |
* @param string $path | |
* the path to scan | |
* @return mixed | |
* an array of files in the given path matching the pattern. | |
*/ | |
function rglob($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,rglob($pattern, $flags, $path)); } | |
return $files; | |
} | |
/* example usage: */ | |
chdir('../'); | |
var_export(rglob('*.php')); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
source : http://forums.phpfreaks.com/topic/190425-recursive-glob/