Now: Tutorial for Web and Software Design > PHP > QA > PHP Content
> PHPFAQ - How do I get the total size of a certain directory? [Bookmark it]
PHPFAQ - How do I get the total size of a certain directory?


Question :

How do I get the total size of a certain directory?

Answer :You can use the folowing function as shown in alt.php by ryanflynnn at my-deja.com:


<?php

$totalsize=0;

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))
            continue;
        if(is_dir($dir.$file)){
        echo "|- ".$pos."s <b>$file</b>\n";
        show_dir("$dir.$file/", $pos+3);
    }else{
        $size=filesize($dir.$file);
        echo "|- ".$pos."s $file ";
        echo("$size <br>");
            $totalsize=$totalsize+$size;
        }
    }
    @closedir($handle);

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

    return($totalsize);
}

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



[Bookmark][Print] [Close][To Top]
  • Prev Article-PHP:

  • Next Article-PHP:
  • Related Materias
    PHPFAQ - How google is you
    PHPFAQ - Are there any web
    PHPFAQ - How can I accept 
    PHPFAQ - How can I finance
    PHPFAQ - Where can I get P
    PHPFAQ - Where can I host 
    PHPFAQ - Where can I find 
    PHPFAQ - I am trying to cr
    PHPFAQ - Is there a librar
    PHPFAQ - How can I manage 
    Topics
    Photoshop Tutorial
     

    Special Effect

      3D Effect
      Photoshop Articles
    Programming Tutorial
     

    C/C++ Tutorial

      Visual Basic
      C# Tutorial
    Database Tutorial
     

    MySQL Tutorial

      MS SQL Tutorial
      Oracle Tutorial
    Graphic Design Tutorial
     

    Coreldraw Tutorial

      Illustrator Tutorial
      3D Graphics Articles
    Webmaster Articles
     

    Domain Service

      Web Hosting
      Site Promotion
    Java Tutorial&Articles
     

    Java Servlets

      JavaEE Tutorial
     

    JavaBeans Tutorial

    XML Tutorial&Articles
     

    XML Style Tutorial

      AJAX Tutorial
      XML Mobile
    Flash Tutorial&Articles
     

    Flash Video

      Action Script
      Flash Articles
    OS Tutorial&Articles
     

    Linux Tutorial

      Symbian Tutorial
      MacOS Tutorial