Skip to content

Instantly share code, notes, and snippets.

@davidrautert
Created December 1, 2010 17:54
Show Gist options
  • Save davidrautert/723903 to your computer and use it in GitHub Desktop.
Save davidrautert/723903 to your computer and use it in GitHub Desktop.
recursive function to find all files in subdirectories and push them into a flat array
$files = array();
function returnFiles($dir) {
global $files;
$dh = opendir($dir);
while(false !== ($filename = readdir($dh))) {
if($filename == '.' || $filename == '..') {
continue;
}
echo $dir.DIRECTORY_SEPARATOR.$filename . "\n";
if(is_file($dir.DIRECTORY_SEPARATOR.$filename)) {
array_push($files, $dir.DIRECTORY_SEPARATOR.$filename);
} else if(is_dir($dir.DIRECTORY_SEPARATOR.$filename)) {
returnFiles($dir.DIRECTORY_SEPARATOR.$filename);
}
}
closedir($dh);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment