Recursion through a directory tree in PHP

Posted by phphelpplz on Stack Overflow See other posts from Stack Overflow or by phphelpplz
Published on 2010-03-27T10:10:55Z Indexed on 2010/03/27 10:13 UTC
Read the original article Hit count: 247

Filed under:
|
|

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); ?>

© Stack Overflow or respective owner

Related posts about php

Related posts about recursion