There is a bug in the code above and after bashing my head for a few minutes, under Windows (I did not test this on any Linux variants), the use of is_file() will always return false unless you change directory before opendir().
For speed, clear the stat cache.
Again, no recursion into subfolders is done. Will work on that later when have more time.
<?php
function GetDirectorySize($dirName)
{
clearstatcache();
if (is_dir($dirName) == false)
return(0);
chdir($dirName);
$dir = opendir($dirName);
$dirSize = 0;
while(false !== ($file = readdir($dir)))
{
$path = getcwd() . "/" . $file;
echo $path . "<br>";
if (is_file($path))
{
if ($path != "." && $path != "..") // skip parent, etc.
$dirSize += filesize($path);
}
}
closedir($dir);
return($dirSize);
}
echo GetDirectorySize("D:/");
?>