Public feed #724761

Untitled

public text v1 · immutable
Raw Edit
·published 2007-10-03 21:14 UTC
rendered paste body
function getDirectorySize($path)
{
	$rv = array('size' => 0, 'count' => 0, 'dircount' => 0);
	$base = $path;
	$stack = array($path);

	while (($dir = opendir(array_pop($stack))) !== false) 
	{
		while (($file = readdir($dir)) !== false)
		{
			if ($file != '.' && $file != '..')
			{
				$nextpath = "$base/$file";
				++$rv['count'];
				if (is_dir($nextpath))
				{
					++$rv['dircount'];
					array_push($stack, $nextpath);
				}
				elseif (is_file($nextpath))
				{
					$rv['size'] += filesize($nextpath);
				}
			}
		}
	}
	return $rv;
}