Recursion through a directory tree in PHP
- by phphelpplz
I have a set of folders that has a depth of at least 4 or 5 levels. I'm looking to recurse through the directory tree as deep as it goes, and iterate over every file. I've gotten the code to go down into the first sets of subdirectories, but no deeper, and I'm not sure why. Any ideas?
$count =
0;
$dir =
"/Applications/MAMP/htdocs/idahohotsprings.com";
function recurseDirs($main, $count){
$dir =
"/Applications/MAMP/htdocs/idahohotsprings.com";
$dirHandle = opendir($main);
echo "here";
while($file = readdir($dirHandle)){
if(is_dir($file) && $file != '.' && $file != '..'){
echo "isdir";
recurseDirs($file);
}
else{
$count++; echo "$count: filename: $file in $dir/$main \n<br />";
} } } recurseDirs($dir, $count); ?