Sunday, March 23, 2014

PHP Code To Find All Directory Or File Recursively

This function can find all directory or file in a path. Here the Code:
function glob_recursive($pattern, $flags = 0){
$files = glob($pattern, $flags);
foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir){
$files = array_merge($files, glob_recursive($dir.'/'.basename($pattern), $flags));
}
return $files;
}

$results = glob_recursive("*", $flags = 0);
foreach ($results as $result) {
$type = is_file($result) ? "File" : "Dir";
echo $result."\n".$type."\n\n";
}
Good Luck !!!

0 comments:

Post a Comment