Forum : How do I get the total size of a certain directory?
Brief description  about Online courses   join in Online courses
View  's Profile

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

sir,

Please tell me how do i get the total size of a certain directory?
Asked by | Nov 23, 2009 |  Reply now
Replies (1)
View teacher siliconindia 's Profile
Hi Naveen,

You can use the folowing function as shown


<?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);
?>
Nov 23, 2009