递归删除文件夹
@param $dir
@return boolean
557320
public static function removeDirs($dir) {

        $handle = opendir($dir);
        //删除文件夹下面的文件
        while ( $file=readdir($handle) ) {
            if( $file != "." && $file != ".." ) {
                $filename = $dir."/".$file;
                if( !is_dir($filename) ) {
                    @unlink($filename);
                } else {
                    self::removeDirs($filename);
                }
            }
        }
        closedir($handle);

        //删除当前文件夹
        if( rmdir($dir) ) {
            return true;
        } else {
            return false;
        }
    }
1157046
protected function isDir($dir)
    {
        try {
            $this->doChangeDir($dir);
            $this->doCdUp();

            return true;
        } catch (\Exception $ex) {
            return false;
        }

        return false;
    }
692538
function mkdir($dir)
    {
        if (!($this->bitmap & NET_SSH2_MASK_LOGIN)) {
            return false;
        }

        if ($dir[0] != '/') {
            $dir = $this->_realpath(rtrim($dir, '/'));
            if ($dir === false) {
                return false;
            }
            if (!$this->_mkdir_helper($dir)) {
                return false;
            }
        } else {
            $dirs = explode('/', preg_replace('#^/|/(?=/)|/$#', '', $dir));
            $temp = '';
            foreach ($dirs as $dir) {
                $temp.= '/' . $dir;
                $result = $this->_mkdir_helper($temp);
            }
            if (!$result) {
                return false;
            }
        }

        return true;
    }
200016
protected function clearDir($dir)
    {
        $iterator = new \DirectoryIterator($dir);
        foreach ($iterator as $file) {

            if ($file->isDir() && !$file->isDot() && !preg_match("~\.~", $file)) {
                $this->clearDir($file->getPathname());
                if (!\rmdir($file->getPathname())) {
                    return false;
                }
            } elseif ($file->isFile()) {
                if (!\unlink($file->getPathname())) {
                    return false;
                }
            }
        }

        return true;
    }
482144
public function clearIndex($dir)
    {
        $success = 0;

        if (!file_exists($dir))
        {
            $success = 1;
        }

        if (!is_dir($dir))
        {
            return @unlink($dir);
        }

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

            if (!$this->clearIndex($dir . DIRECTORY_SEPARATOR . $item))
            {
                $success = 0;
            }

        }

        $sucess = @rmdir($dir);

        return $sucess;
    }
1200202
public static function removeDirectory($dir = '')
    {
        if ($dir == '' || $dir == NULL || $dir == '/')
            return false;

        $files = array_diff(scandir($dir), array('.','..')); 
        foreach ($files as $file)
            (is_dir("$dir/$file")) ? CiiFileDeleter::removeDirectory("$dir/$file") : unlink("$dir/$file"); 

        return rmdir($dir); 
    }
982684
public static function deleteDirectory($dir) {
		if (is_dir($dir))
			$dirHandle = opendir($dir);
		
		if (!$dirHandle)
			return false;
		
		while ($file = readdir($dirHandle)) {
			if ($file != "." && $file != "..") {
				if (!is_dir($dir."/".$file))
					unlink($dir."/".$file);
				else
					self::deleteDirectory($dir.'/'.$file);          
			}
		}
		
		closedir($dirHandle);
		rmdir($dir);
		return true;
	}
607129
public function rm(string $directory): bool {
    if (is_dir($directory)) {
      foreach (new DirectoryIterator(Path::replaceOSSeparator($directory)) as $fileInfo) {
        if (!$fileInfo->isDot()) {
          if ($fileInfo->isDir()) {
            $this->rm($fileInfo->getPathname());
            @rmdir($fileInfo->getPathname());
          } else if ($fileInfo->isFile()) {
            @unlink($fileInfo->getPathname());
          }
        }
      }
      @rmdir($directory);
    }
    return !file_exists($directory);
  }
723812
public function mkdir($dir)
    {
        return ($this->isConnected() === true) ? ftp_mkdir($this->getConnection(), $dir) : false;
    }
435221
public function files($dir)
    {
        $dir = $this->alias->resolve($dir);

        $files = [];
        foreach ($this->glob($dir . (strpos($dir, '*') === false ? '/*' : ''), SCANDIR_SORT_ASCENDING) as $item) {
            if (is_file($item)) {
                $files[] = $item;
            }
        }

        return $files;
    }
1214085
public function cd($dir = '')
    {
        if ($dir == '' || substr($dir, 0, 1) !== '/') {
            $dir = $this->dir . '/' . $dir;
        }

        $this->errorHandler->start();
        if (($dir = $this->driver->realpath($this->resource, $dir)) !== false) {
            $this->dir = $dir;
            $this->errorHandler->stop();

            return true;
        }

        $this->errorHandler->stop();

        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
                );
            }
        }
    }
1249296
public function find_all_files($dir) 
	{
	  $root = scandir($dir); 
    foreach($root as $value) 
    { 
        if($value === '.' || $value === '..')
        {
        	continue;
        } 
        if(is_file("$dir/$value")) 
        {
        	$result[] = "$dir/$value";
        	$this->setAsset("$dir/$value");
        	continue;
        } 
        foreach($this->find_all_files("$dir/$value") as $value) 
        { 
            $result[] = $value; 
        } 
    } 
    return $result; 
	}
874133
public function isDir($dir)
	{
		$current = $this->pwd();
		try {
			$this->chdir($dir);
		} catch (FtpException $e) {
		}
		$this->chdir($current);
		return empty($e);
	}
473147
static function getDir($dir = '.', $ext = NULL) {

		if($dir != '') {
			$dir = rtrim($dir, '/').'/';
		}
		try {
			$i = new \DirectoryIterator($dir);
		} catch (\Exception $e) {
			return false;
		}

		$files = array();

		foreach($i as $file) {
			$fn = $file->getFileName();
			if(!$file->isDot() && $file->isFile() && substr($fn, 0, 1) !== '.') {
				if(!isset($ext) || preg_match("~$ext\$~", $fn)) {
					$files[] = $fn;
				}
			}
		}

		return $files;
	}
790602
function _is_dir($dir)
    {
        $dirs = explode('/', preg_replace('#^/|/(?=/)|/$#', '', $dir));

        $temp = &$this->dirs;
        foreach ($dirs as $dir) {
            if (!isset($temp[$dir])) {
                return false;
            }
            $temp = &$temp[$dir];
        }
    }
1005904
public static function truncate_directory ($dir)
    {
        if (substr($dir, strlen($dir)-1, 1) != '/') {
            $dir .= '/';
        }

        if (!$fileList = scandir ($dir)) {
            return false;
        }

        foreach ($fileList as $fileInList) {
            if (is_dir($dir . $fileInList) && $fileInList != '.' && $fileInList != '..') {
                // Some more directory. Recurse!
                if (!self::rmrf($dir . $fileInList . '/')) {
                    // If false, Error message was already given by rmrf.
                    return false;
                }
            } elseif (is_file($dir . $fileInList)) {
                if (!unlink ($dir . $fileInList)) {
                    return false;
                }
            }
        }

        return true;
    }