Created
July 8, 2013 23:27
-
-
Save hmert/5953356 to your computer and use it in GitHub Desktop.
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 | |
function recursive_directory($dirname,$maxdepth=10, $depth=0){ | |
if ($depth >= $maxdepth) { | |
return false; | |
} | |
$subdirectories = array(); | |
$files = array(); | |
if (is_dir($dirname) && is_readable($dirname)) { | |
$d = dir($dirname); | |
while (false !== ($f = $d->read())) { | |
$file = $d->path.'/'.$f; | |
// skip . and .. | |
if (('.'==$f) || ('..'==$f)) { | |
continue; | |
}; | |
if (is_dir($dirname.'/'.$f)) { | |
array_push($subdirectories,$dirname.'/'.$f); | |
} else { | |
array_push($files,$dirname.'/'.$f); | |
}; | |
}; | |
$d->close(); | |
foreach ($subdirectories as $subdirectory) { | |
$files = array_merge($files, recursive_directory($subdirectory, $maxdepth, $depth+1)); | |
}; | |
} | |
return $files; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment