/** * Get directory size. * * <code> * echo Dir::size('folder1'); * </code> * * @param string $path The path to directory. * @return integer */ public static function size($path) { // Redefine vars $path = (string) $path; $total_size = 0; $files = scandir($path); $clean_path = rtrim($path, '/') . '/'; foreach ($files as $t) { if ($t != "." && $t != "..") { $current_file = $clean_path . $t; if (is_dir($current_file)) { $total_size += Dir::size($current_file); } else { $total_size += filesize($current_file); } } } // Return total size return $total_size; }
/** * Return directory size (= sum of all filesizes in directory tree). * * @param string $path * @return int */ public static function size($path) { $entries = Dir::entries($path); $size = 0; foreach ($entries as $entry) { if (FSEntry::isDir($entry, false)) { $size += Dir::size($entry); } else { if (FSEntry::isFile($entry, false)) { $size += File::size($entry); } } } return $size; }