Return to Snippet

Revision: 21529
at December 15, 2009 11:32 by ginoplusio


Initial Code
function dirsize($dir,$buf=2) {
	static $buffer;
	if(isset($buffer[$dir])) return $buffer[$dir];
	if(is_file($dir)) return filesize($dir);
	if($dh=opendir($dir)) {
		$size=0;
		while(($file=readdir($dh))!==false) {
			if($file=='.' || $file=='..') continue;
			$size+=dirsize($dir.'/'.$file,$buf-1);
		}
		closedir($dh);
		if($buf>0) $buffer[$dir]=$size;
		return $size;
	}
	return false;
}

Initial URL
http://www.barattalo.it/2010/02/01/calculate-dir-size-recursively/

Initial Description
Calculate dir size recursive, follow the link above because the version above is better.

Initial Title
Dir size recursive php function

Initial Tags
directory

Initial Language
PHP