Hey all, I am trying to write a DU function in php so I can control how the output works and what I do with it.

I have gotten this far and it does do a directory listing, but I have some issues:

1) it first prints the main dir and puts a size of 0 because it hasn't gone into the deepest part of the directory yet.

2) i am a bit lost on how i would go and add all the sizes together to make the nested directories show in the main dir size as well

any help is really appreciated!

rob

PHP Code:
<?php 
 
 
function traverseDirTree($base,$fileFunc,$dirFunc=null,$afterDirFunc=null)
 {
      
$subdirectories=opendir($base); 
      while ((
$subdirectory=readdir($subdirectories))!==false)
          { 
              
$path=$base.$subdirectory
              if (
is_file($path))
                  { 
                  if (
$fileFunc!==null$fileFunc($path); 
                  }else{ 
                  if (
$dirFunc!==null$dirFunc($path); 
                  if ((
$subdirectory!='.') && ($subdirectory!='..'))
                          { 
                       
traverseDirTree($path.'/',$fileFunc,$dirFunc,$afterDirFunc); 
                          } 
                  if (
$afterDirFunc!==null$afterDirFunc($path); 
                  } 
          }
 }
 
 function 
getdirsize($path)
 {
     
$length strlen($path);
     
     if (
substr($path,-1,1) != ".")
     
     {
         
$size 0;
         if (
$handle opendir($path)) 
         {
             while (
false !== ($file readdir($handle))) 
                 {
                     
$size $size filesize("$path/$file");
                 }
             
             
closedir($handle);
         }
         echo 
$path " " round($size/1024,2) ." mb\n";
      }
 }
 
 
 echo 
"\n"
 
traverseDirTree('f:/mydir/',null,'getdirsize'); 
 echo 
"\n";
 
 
?>