[snip]
Can anybody help me to open all subdirectories in a directory, I used
is_dir() to check whether it is a dir, and if yes, I recursively called
it with the new dir name. But  all subdirectories are not open the
recursion is not working for more than 1 level. I tested it in windows
server. Expecting your help, Jacob.
[/snip]

I use this on a slackware box.  I jacked the code from the man page for
filesize() and cleaned it up.  It's more for finding the size of a
directory, but it does recursively scan through them and I'm sure you
can mod it up to fite your needs.

function funcGetDirSize($dirDirectory) {
       $intSizeInBytes = 0;
       $intNumFilesScanned = 0;
       $intNumDirsScanned = 0;
       if ($handle = @opendir($dirDirectory)) {
           while ($file = readdir($handle)) {
               if($file != "." && $file != "..") {
                   if(@is_dir($dirDirectory."/".$file)) {
                       $arrCurDirInfo =
funcGetDirSize($dirDirectory."/".$file);
                       $intSizeInBytes +=  $arrCurDirInfo[2];
                       $intNumFilesScanned +=  $arrCurDirInfo[0];
                       $intNumDirsScanned +=  $arrCurDirInfo[1];
                       $intNumDirsScanned++;
                   } else {
                       $intSizeInBytes +=
@filesize($dirDirectory."/".$file);
                       $intNumFilesScanned++;
                   }
               }
           }
       closedir($handle);
       }
       $arrDirInfo[0] = $intNumFilesScanned;
       $arrDirInfo[1] = $intNumDirsScanned;
       $arrDirInfo[2] = $intSizeInBytes;
       return $arrDirInfo;
} 

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to