Click to See Complete Forum and Search --> : [RESOLVED] folder size


AmazingAnt
01-04-2007, 10:09 PM
I've been using the filesize() function for some time now for a few different reasons, and I was just wondering if anyone knows how I might find out the size of a folder. Yes, I know the folder itself only takes up enough space to hold the name and all that jazz, but I'm looking more to the effect of how looking at the properties of a folder (in Windows) will add up the size of all the files inside that folder, and give you that number.
Or am I just hoping for a little too much?

NightShift58
01-04-2007, 11:00 PM
<?php
$recursive = true;
print dirsize(".",$recursive);

function dirsize($pDIRpath='.',$pRECURSIVE=true,$pDIRsize=0) {
$arrDIR = glob("$pDIRpath/*");
$dir_size = $pDIRsize;
FOREACH ($arrDIR as $thisFILE) :
print $thisFILE . "<br>"; //for testing, remove when no longer needed...
IF (is_dir($thisFILE)) :
IF ($pRECURSIVE) :
$dir_size = dirsize($thisFILE, true, $dir_size);
ENDIF;
ELSE :
$dir_size = $dir_size + filesize($thisFILE);
ENDIF;
ENDFOREACH;
return $dir_size;
}
?>

AmazingAnt
01-05-2007, 11:16 AM
Thanks!~

NightShift58
01-05-2007, 11:21 AM
You're welcome!