Размер директории в байтах
@param string $dir Путь на директорию
@return int
972787
static function getDirSize($dir)
    {
        $size = 0;
        $dirs = array_diff(scandir($dir), array('.', '..'));
        foreach ($dirs as $d){
            $d = $dir.'/'.$d;
            $size+= filesize($d);
            if (is_dir($d)){
                $size+= self::getDirSize($d);
            }
        }
        return $size;
    }
95183
public static function dirSize($directory)
    {
        $size = 0;
        foreach (new \RecursiveIteratorIterator(
                     new RecursiveDirectoryIterator($directory, \FilesystemIterator::KEY_AS_PATHNAME)
                 ) as $file) {
            $size += $file->getSize();
        }

        return $size;
    }
1016180
protected function scanDir(string $dir): ScanResult
    {
        $fileInfo = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir));
        $files = [];
        foreach ($fileInfo as $pathname => $item) {
            if (!$item->isFile()) {
                continue;
            }

            $files[] = $pathname;
        }

        return $this->scanArray($files);
    }
53260
public function getCommonInfo($dir)
	{
		$userInfo = array();
		$send_snoopy = new Snoopy; 
		$send_snoopy->rawheaders['Cookie']= $this->cookie;
		$send_snoopy->referer = "https://mp.weixin.qq.com/cgi-bin/message?t=message/list&count=20&day=7&lang=zh_CN&token=".$this->_token;
		$url = "https://mp.weixin.qq.com/cgi-bin/home?t=home/index&lang=zh_CN&token=".$this->_token;
		$send_snoopy->fetch($url);
		$result = $send_snoopy->results;
		// 分析首页内容，获取nickname,avatar,usertype
		preg_match_all('/class=\"nickname\">(.*)<\/a>/', $result, $matches1);
        preg_match_all('/<img src=\"(.*)\" class=\"avatar\"/', $result, $matches2);
        preg_match_all('/<label for=\"\" class=\"type icon_service_label\">(.*)<\/label>/', $result, $matches3);
        $userInfo["nickname"] = $nickname = $matches1[1][0];
        if(strpos($nickname, '<') !== false)
        {
        	$userInfo["nickname"] = $nickname = substr($nickname, 0, strpos($nickname, '<'));
        }
        $userInfo["avatar"] = $avatar = $matches2[1][0];
        if( ! empty($matches3[1][0]))
        {
            $userInfo["type"] = $usertype = $matches3[1][0];
        }
        else
        {
            $userInfo["type"] = $usertype = "订阅号";
        }
		$this->log('Analysis account info:'. "\nNickname:". $nickname. "\nAvatar:". $avatar. "\nUsertype:". $usertype);
		// 分析设置页面，获取二维码
		$send_snoopy = new Snoopy; 
		$send_snoopy->rawheaders['Cookie']= $this->cookie;
		$send_snoopy->referer = "https://mp.weixin.qq.com/cgi-bin/message?t=message/list&count=20&day=7&lang=zh_CN&token=".$this->_token;
		$url = "https://mp.weixin.qq.com/cgi-bin/settingpage?t=setting/index&action=index&lang=zh_CN&token=".$this->_token;
		$send_snoopy->fetch($url);
		$result = $send_snoopy->results;
		// $this->log("QRCODE contents:". $result);
		preg_match_all('/<img src=\"(.*)\" width=\"150\"/', $result, $matches4);
        $userInfo["qrcode"] = $qrcode = $matches4[1][0];
        // downloads the avatar
        $send_snoopy = new Snoopy; 
		$send_snoopy->rawheaders['Cookie']= $this->cookie;
		$send_snoopy->referer = "https://mp.weixin.qq.com/cgi-bin/settingpage?t=setting/index&action=index&lang=zh_CN&token=".$this->_token;
		$url = "https://mp.weixin.qq.com". $avatar;
		$send_snoopy->fetch($url);
		$result = $send_snoopy->results;
        $userInfo["avatar"] = $this->downloadImage($result, $dir. DIRECTORY_SEPARATOR. 'avatars');
        // downloads the qrcode
        $send_snoopy = new Snoopy; 
		$send_snoopy->rawheaders['Cookie']= $this->cookie;
		$send_snoopy->referer = "https://mp.weixin.qq.com/cgi-bin/settingpage?t=setting/index&action=index&lang=zh_CN&token=".$this->_token;
		$url = "https://mp.weixin.qq.com". $qrcode;
		$send_snoopy->fetch($url);
		$result = $send_snoopy->results;
        $userInfo["qrcode"] = $this->downloadImage($result, $dir. DIRECTORY_SEPARATOR. 'qrcodes');
        // 获取appid和appsecret
        $send_snoopy = new Snoopy; 
		$send_snoopy->rawheaders['Cookie']= $this->cookie;
		$send_snoopy->referer = "https://mp.weixin.qq.com/cgi-bin/settingpage?t=setting/index&action=index&lang=zh_CN&token=".$this->_token;
		$url = "https://mp.weixin.qq.com/advanced/advanced?action=dev&t=advanced/dev&lang=zh_CN&token=".$this->_token;
		$send_snoopy->fetch($url);
		$result = $send_snoopy->results;

		preg_match_all('/name:\"AppId\",value:\"(.*)\"/', $result, $matches_id);
		preg_match_all('/name:\"AppSecret\",value:\"(.*)\"/', $result, $matches_secret);
		
        $userInfo["appid"] = $AppId = $matches_id[1][0];
        $userInfo["appsecret"] = $AppSecret = $matches_secret[1][0];
        
		if(! empty($userInfo)){
			return $userInfo;
		}
		return false;
	}
202331
public function recursiveScandir(string $dir)
    {
        $contents = array();

        foreach (scandir($dir) as $file) {
            if ($file == '.' || $file == '..') {
                continue;
            }

            $path = $dir.DIRECTORY_SEPARATOR.$file;

            if (is_dir($path)) {
                $contents = array_merge($contents, $this->recursiveScandir($path));
            } else {
                $contents[] = $path;
            }
        }
        return ($contents);
    }
1026588
protected function dirExists($dir)
    {
        if ($this->files->exists($dir)) {

            if ( ! $this->files->isDirectory($dir)) {
                throw new RuntimeException("The given directory [$dir] is not a directory.");
            }

            return true;
        }

        return false;
    }
779315
private function scandir($dir) {
        $dir = trim($dir, '/') . '/';
        $absolute = $this->absolute($dir);
        $files = scandir($absolute);

        foreach ($files as $file) {
            // ignore relative references
            if ($file === "." || $file === "..") {
                continue;
            }

            if (is_dir($absolute . $file)) {
                $this->scandir($dir . $file);
            } else {
                // we want the relative path inside the input_dir so we can
                // put the file in the same place in the output_dir
                $path = preg_replace("#^" . Config::get('input_dir') .  "#", "", $dir . $file);
                $this->paths[] = array(
                    'path' => $path
                );
            }
        }
    }
355203
public function rmdirr($dir)
    {
        if ($handle = opendir("$dir")) {
            while ($item = readdir($handle)) {
                if (($item != ".") && ($item != "..")) {
                    if (is_dir("$dir/$item")) {
                        $this->rmdirr("$dir/$item");
                    } else {
                        unlink("$dir/$item");
                    }
                }
            }
            closedir($handle);
            rmdir($dir);
        }
    }
244809
public static function removeDir($dir)
    {
        if (is_dir($dir)) {
            $objects = scandir($dir);
            foreach ($objects as $object) {
                if ('.' != $object && '..' != $object) {
                    if ('dir' == filetype($dir . DS . $object)) {
                        static::removeDir($dir . DS . $object);
                    } else {
                        if (! unlink($dir . DS . $object)) {
                            throw new ErrorException(
                                'The following file could not be deleted: ' . $dir . DS . $object
                            );
                        }
                    }
                }
            }

            if (! rmdir($dir)) {
                throw new ErrorException("The following directory could not be deleted: {$dir}");
            }
        }
    }
1250975
public function getDirLevel()
	{
		if (!trim($this->getPath()))
		{
			return 0;
		}

		$dirParts = explode('/', $this->getPath());

		return count($dirParts);
	}
1332062
public static function rmdir($dir)
    {
        // List the contents of the directory table
        $dir_content = scandir ($dir);
        // Is it a directory?
        if ($dir_content!==false) {
            // For each directory entry
            foreach ($dir_content as &$entry) {
                // Unix symbolic shortcuts, we go
                if (!in_array ($entry, array ('.','..'))) {
                    // We find the path from the beginning
                    $entry = $dir.DIRECTORY_SEPARATOR. $entry;
                    // This entry is not an issue: it clears
                    if (!is_dir($entry)) {
                        unlink ($entry);
                    } else { // This entry is a folder, it again on this issue
                        self::rmdir($entry);
                    }
                }
            }
        }
        // It has erased all entries in the folder, we can now erase
        rmdir ($dir);
    }
81586
private function nList($dir)
    {
        $dirList = ftp_nlist($this->session, $dir);
        if ($dirList === false) {
            throw new \RuntimeException('List error');
        }
        return $dirList;
    }
54185
protected function processDir($dir) {
    $dir = $this->replacePattern($dir);
    // The absolute path has to be calculated relative to the configuration file
    if (Path::isRelative($dir)) {
      $dir = Path::makeAbsolute($dir, dirname($this->configFile));
    }
    return rtrim($dir, '/');
  }
682109
public static function removeDir(string $dir)
    {
        foreach (scandir($dir) as $file) {
            if ('.' === $file || '..' === $file) {
                continue;
            }
            if (is_dir($dir . '/' . $file)) {
                self::removeDir($dir . '/' . $file);
            } else {
                unlink($dir . '/' . $file);
            }
        }
        rmdir($dir);
    }
606196
protected function getTotal($directory, array $options = array())
    {
        $options['count'] = true;
        return (int) $this->scanner->scan($directory, $options);
    }
1133878
public static function dirsize($dir, $createifmissing = false) {
		$dirsize = 0;
		if (!file_exists($dir)) {
			if ($createifmissing === true) {
				mkdir($dir);
				return 0;
			}
			throw new \Exception('Directory does not exist!', 400);
		}

		$dir_info = scandir($dir);

		if ($dir{(mb_strlen($dir) - 1)} !== '/') {
			$dir .= '/';
		}

		clearstatcache();
		foreach ($dir_info as $i => $member) {
			if ($member === '.' || $member === '..') {
				continue;
			}
			$abs_member = $dir.$member;
			if (is_file($abs_member)) {
				$dirsize += filesize($abs_member);
			} elseif (is_dir($abs_member)) {
				$dirsize += static::dirsize($abs_member.'/');
			}
		}
		return $dirsize;
	}
530148
public function dirSize($directory = '.', $recursive = true)
    {
        $items = $this->scanDir($directory, $recursive);
        $size  = 0;

        foreach ($items as $item) {
            $size += (int) $item['size'];
        }

        return $size;
    }