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

Explain me is multiple inheritance supported in php?

0 Answers  


What is the function file_get_contents() usefull for?

0 Answers  


What are the methods of array in java?

0 Answers  


How to check a variable is array or not in php?

0 Answers  


What is the basic function to search files for lines (or other units of text) that contain a pattern.

0 Answers  






What is htmlspecialchars?

0 Answers  


What is boolean in php?

0 Answers  


What are the ways we can destroy a session variable ?

3 Answers  


What is super () python?

0 Answers  


How can I make a script that can be bilanguage (supports English, German)?

3 Answers  


How to insert a line break in php string?

0 Answers  


How to write the form tag correctly for uploading files?

0 Answers  


Categories