Total size of a directory

The following code includes a function to calculate the total hard disk space taken up by a directory.



function show_dir($dir, $pos=2){
   global $totalsize;
   if($pos == 2)
      echo "<hr><pre>";

   $handle = @opendir($dir);
   while ($file = @readdir ($handle)){
      if (eregi("^\.{1,2}$",$file))
      if (is_dir($dir.$file)) {
         echo "|- ".$pos."s <b>$file</b>\n";
         show_dir("$dir.$file/", $pos+3);
      } else {
         echo "|- ".$pos."s $file ";
         echo("$size <br>");

if($pos == 2) echo "</pre><hr>";

$totalsize = show_dir("c:/winnt/system32/");

You might also like...




Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“If debugging is the process of removing software bugs, then programming must be the process of putting them in.” - Edsger Dijkstra