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

What are the basic steps to store PHP session in to Database?

1 Answers   Rediff,


What is isset php?

0 Answers  


How do I add to the beginning of an array and find the number of elements in it?

1 Answers   Rushmore Consultancy,


What is the maximum size of a table in mysql?

0 Answers  


Can we use get instead of post?

0 Answers  






How a variable is declared in php?

0 Answers  


what is interface in php? how it is use?

10 Answers   Infosys, PHP, Times, Torque Infotech, Wipro,


What is difference between array_merge and array_combine in php?

0 Answers  


What is php and why it is used?

0 Answers  


Design a class that should always return a single object ?

3 Answers   NIIT,


How many types of functions are there in php?

0 Answers  


How can you compare objects in php?

0 Answers  


Categories