/** * Returns the total size of the directory. * * @param $recursive (optional) Recurse into the subdirectories. Default is false. * @param $formatted (optional) If set to true, the filesize will be returned in a human readable format. * @param $decimals (optional) The number of decimals to use for formatting the filesize. * * @returns The total size of the directory. */ function getSize($recursive = false, $formatted = false, $decimals = 1) { $total = 0; $dirHandle = opendir($this->getPath()); while (false !== ($file = readdir($dirHandle))) { if ($file == '.' || $file == '..') { continue; } if (is_file($this->getPath() . '/' . $file)) { $total += filesize($this->getPath() . '/' . $file); } else { if ($recursive && is_dir($this->getPath() . '/' . $file)) { $subdir = new YDFSDirectory($this->getPath() . '/' . $file); $total += $subdir->getSize(true, false, $decimals); } } } closedir($dirHandle); if (!$formatted) { return $total; } return YDStringUtil::formatFilesize($total, $decimals); }