src/Helpers/FileSystem.php
public static function dirSize($path, array $exclude = [])
    {
        if (!is_dir($path)) {
            return 0;
        }

        $size = 0;
        $exclude = array_merge(['.', '..'], $exclude);
        $items = array_diff(scandir($path), $exclude);
        foreach ($items as $item) {
            $inner_item = static::join($path, $item);
            $size += is_file($inner_item) ? filesize($inner_item) : static::dirSize($inner_item, $exclude);
        }

        return $size;
    }
public static function dirSize($path, array $exclude = [])
    {
        if (!is_dir($path)) {
            return 0;
        }

        $size = 0;
        $exclude = array_merge(['.', '..'], $exclude);
        $items = array_diff(scandir($path), $exclude);
        foreach ($items as $item) {
            $inner_item = static::join($path, $item);
            $size += is_file($inner_item) ? filesize($inner_item) : static::dirSize($inner_item, $exclude);
        }

        return $size;
    }
public static function dirSize ( $ path , array $ exclude = [ ] ) { if ( ! is_dir ( $ path ) ) { return 0 ; } $ size = 0 ; $ exclude = array_merge ( [ '.' , '..' ] , $ exclude ) ; $ items = array_diff ( scandir ( $ path ) , $ exclude ) ; foreach ( $ items as $ item ) { $ inner_item = static :: join ( $ path , $ item ) ; $ size += is_file ( $ inner_item ) ? filesize ( $ inner_item ) : static :: dirSize ( $ inner_item , $ exclude ) ; } return $ size ; }
Calculate directory size including sub-folders

@param string $path
@param array $exclude

@return int
Calculate directory size including sub - folders