dir::size PHP Method

size() static public method

Gets the size of the directory and all subfolders and files
static public size ( $path, boolean $recursive = true, boolean $nice = false ) : mixed
$recursive boolean
$nice boolean returns the size in a human readable size
return mixed
    static function size($path, $recursive = true, $nice = false)
    {
        if (!file_exists($path)) {
            return false;
        }
        if (is_file($path)) {
            return self::size($path, $nice);
        }
        $size = 0;
        foreach (glob($path . "/*") as $file) {
            if ($file != "." && $file != "..") {
                if ($recursive) {
                    $size += self::size($file, true);
                } else {
                    $size += f::size($path);
                }
            }
        }
        return $nice ? f::nice_size($size) : $size;
    }

Usage Example

コード例 #1
0
ファイル: DirTest.php プロジェクト: LucasFyl/korakia
 public function testSize()
 {
     dir::make($this->tmpDir);
     f::write($this->tmpDir . DS . 'testfile-1.txt', str::random(5));
     f::write($this->tmpDir . DS . 'testfile-2.txt', str::random(5));
     f::write($this->tmpDir . DS . 'testfile-3.txt', str::random(5));
     $this->assertEquals(15, dir::size($this->tmpDir));
     $this->assertEquals('15 b', dir::niceSize($this->tmpDir));
     dir::remove($this->tmpDir);
 }
All Usage Examples Of dir::size