Created
December 1, 2010 17:54
-
-
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
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
$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