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

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

When is a conditional statement ended with endif?

507


Which function would you use to merge two arrays in php?

575


What are the features of php?

556


Is php faster than javascript?

515


How to store the uploaded file to the final location?

518






How to submit form without a submit button.

540


What is a php session?

572


What is htaccess in php?

612


What are the benefits of using php and mysql?

513


Can we use session in mvc?

560


What is csrf verification?

533


Is wordpress a php framework?

521


How does php strcmp work?

508


Tell me what is the difference between ereg_replace() and eregi_replace()?

548


Is age interval or ordinal data?

527