删除文件夹（包括有子目录或有文件）

@param string $dir 目录
@param bool $rmSelf = false 是否删除本身
@return bool
16625
private function removeDir($dir, $rmSelf = true)
    {
        $dir = rtrim($dir, '/');
        
        // 不处理非法路径
        $dir = $this->safePath($dir);
    
        if(!$dir || !$d = dir($dir)) {
            return;
        }

        $do = true;
        while (false !== ($entry = @$d->read())) {
            if($entry[0] == '.') {
                continue;
            }
            
            $path = $dir.'/'.$entry;
            if (is_dir($path)) {
                $do && $do = static::removeDirs($path, true);
            } else {
                $do && $do = false !== @unlink($path);
            }
        }
            
        @$d->close();
        
        $rmSelf && @rmdir($dir);
        
        return $do;
    }
830922
function rmdir($dir)
    {
        if (!($this->bitmap & NET_SSH2_MASK_LOGIN)) {
            return false;
        }

        $dir = $this->_realpath($dir);
        if ($dir === false) {
            return false;
        }

        if (!$this->_send_sftp_packet(NET_SFTP_RMDIR, pack('Na*', strlen($dir), $dir))) {
            return false;
        }

        $response = $this->_get_sftp_packet();
        if ($this->packet_type != NET_SFTP_STATUS) {
            user_error('Expected SSH_FXP_STATUS', E_USER_NOTICE);
            return false;
        }

        extract(unpack('Nstatus', $this->_string_shift($response, 4)));
        if ($status != NET_SFTP_STATUS_OK) {
            // presumably SSH_FX_NO_SUCH_FILE or SSH_FX_PERMISSION_DENIED?
            $this->_logError($response, $status);
            return false;
        }

        $this->_remove_dir($dir);

        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;
    }
648784
public static function isLink(string $dir = ''): bool
    {
        $dir = static::normalizePath($dir);
        return static::exists($dir) && \is_link($dir);
    }
390279
static function cleanupEmptyDirectories( $dir )
    {
        $dir = self::cleanPath( $dir, self::SEPARATOR_UNIX );
        $dirElements = explode( '/', $dir );
        if ( count( $dirElements ) == 0 )
            return true;
        $currentDir = $dirElements[0];
        $result = true;
        if ( !file_exists( $currentDir ) and $currentDir != "" )
            $result = self::doMkdir( $currentDir, self::directoryPermission() );
        if ( !$result )
            return false;

        for ( $i = count( $dirElements ); $i > 0; --$i )
        {
            $dirpath = implode( '/', array_slice( $dirElements, 0, $i ) );
            if ( file_exists( $dirpath ) and
                 is_dir( $dirpath ) )
            {
                $rmdirStatus = @rmdir( $dirpath );
                if ( !$rmdirStatus )
                    return true;
            }
        }
        return true;
    }
81586
private function nList($dir)
    {
        $dirList = ftp_nlist($this->session, $dir);
        if ($dirList === false) {
            throw new \RuntimeException('List error');
        }
        return $dirList;
    }
723812
public function mkdir($dir)
    {
        return ($this->isConnected() === true) ? ftp_mkdir($this->getConnection(), $dir) : false;
    }
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; 
	}
226077
protected final static function readyDir($dir) {
		if(is_file($dir))
			return false;
		
		if (!is_dir(dirname($dir)))
			return mkdir(dirname($dir), 0777, true);
		
		return true;
	}
16707
private function _rrmdir($dir)
    {
        if ($handle = opendir($dir)) {
            while (false !== ($file = readdir($handle))) {
                if ($file != '.' && $file != '..') {
                    if (is_dir($dir . '/' . $file)) {
                        $this->_rrmdir($dir . '/' . $file);
                        rmdir($dir . '/' . $file);
                    } else {
                        unlink($dir . '/' . $file);
                    }
                }
            }
            closedir($handle);
        }
    }
410450
static public function rmdir($dir, $recursive = false)
    {
        $dir = realpath($dir);
        if (!is_dir($dir)) return true;
        if (true !== $recursive) return @rmdir($dir);
        $dp = @opendir($dir);
        while ($file = @readdir($dp)) {
            if ('.' === $file || '..' === $file) continue;
            $cur_file = $dir . '/' . $file;
            if (is_dir($cur_file)) {
                self::rmdir($cur_file, true);
            } elseif (is_file($cur_file)) {
                @unlink($cur_file);
            }
        }
        @closedir($dp);
        return @rmdir($dir);
    }
582924
protected function rmdir($dir) {
        $iterator = new RecursiveIteratorIterator(
            new RecursiveDirectoryIterator($dir),
            RecursiveIteratorIterator::CHILD_FIRST
        );

        foreach ($iterator as $file) {
            $name = $file->getPathname();

            if (substr($name, -1) === '.') {
                continue;
            }

            if ($file->isDir()) {
                // Remove dir
                rmdir($name);
            } else {
                // Remove file
                unlink($name);
            }
        }

        // Remove the directory itself
        rmdir($dir);
    }
116529
public static function list_files($dir, $dirfile = false, $md5 = true, $root = true)
    {
        static $return = [];
        if ($root) {
            $return = [];
        }
        $filepoint = opendir($dir);
        while (($target = readdir($filepoint)) !== false) {
            if ("." == $target || ".." == $target) {
                continue;
            }
            if (is_dir($dir . $target)) {
                self::list_files($dir . $target . '/', $dirfile, $md5, false);
            } else {
                if ($md5) {
                    $file = $dirfile ? $dir . $target : $target;
                    $return[md5_file($dir . $target)] = $file;
                } else {
                    $file = $dirfile ? $dir . $target : $target;
                    $return[] = $file;
                }
            }
        }
        closedir($filepoint);
        return $return;
    }
280087
protected function _rmdir( $dir )
    {
        $iterator = new RecursiveIteratorIterator(
            new RecursiveDirectoryIterator( $dir,
                RecursiveDirectoryIterator::CURRENT_AS_FILEINFO |
                RecursiveDirectoryIterator::SKIP_DOTS
            ),
            RecursiveIteratorIterator::CHILD_FIRST
        );

        $result = true;

        foreach ( $iterator as $info )
        {
            $path = $info->getPathname();

            switch ( true )
            {
                case $info->isFile():
                case $info->isLink():
                    $result = $result && @ unlink( $path );
                    break;

                case $info->isDir():
                    $result = $result && @ rmdir( $path );
                    break;
            }

        }

        return $result && @ rmdir( $dir );
    }
700198
public static function createDir($dir, $mode = 0775)
    {
        if (empty($dir)) return false;
        if (!is_dir($dir)) {
            if(@mkdir($dir, $mode, true)){
                return true;
            }else{
                return false;
            }
        } else {
           return true;
        }
    }
138499
private function rrmdir($dir)
    {
        // protect from something bad happening
        if (0 !== strpos($dir, $this->storagePath)) {
            return false;
        }

        foreach (glob($dir . DIRECTORY_SEPARATOR . '*') as $file) {
            if (is_dir($file)) {
                $this->rrmdir($file);
            } else {
                unlink($file);
            }
        }

        return rmdir($dir);
    }
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];
        }
    }