Directory Size
By: Daniel
Creating a script to display the size of a directory is fairly simple. First off you need to know the path to the directory. After that is known you can use the following fuction to display the filesize:
function dirsize($dir) { $dirs = array($dir); while(!empty($dirs)) { // Loop through all directories $path = array_shift($dirs); foreach(glob($path.'/*') AS $next) { if(is_dir($next)) { $dirs[] = $next; // Add another directory to the loop } else { $size += filesize ($next); // Add filesize to count } } } return $size; // Return the total filesize of the directory }
This function returns a string with the size of the directory in bytes. You can however use the Convert byte count function to produce a readable format.
An example of this code could be:
$path = '.'; echo dirsize($path); // would produce something like 732952 or 715.79 KB using the Convert byte count function




March 3rd, 2007 at 7:33 am
Do I have to be a member to post to this blog?
March 19th, 2007 at 3:24 pm
Thanks alot webmaster I like your site