note 15203 deleted from function.disk-total-space by cece
| From: | cece@php.net | Date: | Tue, 19 Aug 2003 12:43:01 +0000 |
| Subject: | note 15203 deleted from function.disk-total-space by cece | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-54664@lists.php.net to get a copy of this message | ||
Note Submitter: flagzen@libero.it
----
This is an enhanced version of the dirsize function written above, with recursion so that making
dirsize($dir) returns the total size of the dir, including all subdirectories.
I hope that this function will be useful to someone.
function dirsize($dir) {
// calculate the size of files in $dir, (it descends recursively into other dirs)
$dh = opendir($dir);
$size = 0;
while (($file = readdir($dh)) !== false)
if ($file != "." and $file != "..") {
$path = $dir."/".$file;
if (is_dir($path))
$size += dirsize($path);
elseif (is_file($path))
$size += filesize($path);
}
closedir($dh);
return $size;
}