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

What are the design patterns in php?

512


How to set session.gc_divisor properly?

590


How to create a session? How to set a value in session? How to remove data from a session?

511


What’s the difference between htmlentities() and htmlspecialchars()?

575


What is php rest api?

528






How to pass an argument to a function?

548


Which function is used in php to delete a file?

554


What is the ioncube php loader?

569


What is framework? How it works? What is advantage?

492


How do I use isdigit function?

558


Can we extend final class in php?

508


What is php key?

505


Does php have multiple inheritance?

500


How many ways to include variables in double-quoted strings in php?

549


What is $_ request?

519