How can you get, the total size of a certain directory?



How can you get, the total size of a certain directory?..

Answer / suren

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);
?>

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More PHP Interview Questions

Who is the father of php and what is the current version of php and mysql?

0 Answers  


Where php basically used?

0 Answers  


What are magic methods in php

2 Answers   Net Solution,


How to create reusable code in php?

0 Answers  


what is hidden variable? what is its difference with the normal variable...

2 Answers   Shine,






How to pass variables by references?

0 Answers  


What is $this in php?

0 Answers  


What are the three parts of an http request?

0 Answers  


What does $_ post mean in php?

0 Answers  


How does php strcmp work?

0 Answers  


How many data types are there in php?

0 Answers  


What is cakephp framework?

0 Answers  


Categories