@param string $directory - full directory path

@return bool
541670
private function isDir($directory)
    {
        if ('/' === $directory) {
            return true;
        }

        if (!@ftp_chdir($this->getConnection(), $directory)) {
            return false;
        }

        // change directory again to return in the base directory
        ftp_chdir($this->getConnection(), $this->directory);

        return true;
    }
751314
private function ftpDelete($directory)
    {
        // here we attempt to delete the file/directory
        if (!(@ftp_rmdir($this->ftp, $directory) || @ftp_delete($this->ftp, $directory))) {
            // if the attempt to delete fails, get the file listing
            $filelist = @ftp_nlist($this->ftp, $directory);

            // loop through the file list and recursively delete the FILE in the list
            foreach ($filelist as $file) {
                $this->ftpDelete($file);
            }

            // if the file list is empty, delete the DIRECTORY we passed
            $this->ftpDelete($directory);
        }
        return true;
    }
356878
public function directories($directory)
    {
        return collect($this->filesystem->directories($directory))
            ->map(function ($file) {
                return new File($file, $this);
            });
    }
831197
public function scanDirectory($directory)
    {
        $extensions = $this->getOption('extensions');

        foreach (scandir($directory) as $object) {
            if ($object === '.' || $object === '..') {
                continue;
            }
            $inputFile = $directory.DIRECTORY_SEPARATOR.$object;
            if (is_dir($inputFile)) {
                foreach ($this->scanDirectory($inputFile) as $file) {
                    yield $file;
                }

                continue;
            }
            if ($this->fileMatchExtensions($object, $extensions)) {
                yield $inputFile;
            }
        }
    }
44714
public static function addDirectory($directory = '.')
    {
        $directory = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $directory);
        $directory = rtrim($directory, '/\\');
        $directory = empty($directory) ? '.' : $directory;
        array_push(self::$configDirectory, $directory);
        return true;
    }
359698
public function cleanDir($dir)
    {
        if (empty($dir)) return false;

        $dir === 'all' && $dir = '';//删除所有
        $fullDir = $this->conf['CACHE_PATH'] . $dir;
        if (!is_dir($fullDir)) {
            return false;
        }

        $files = scandir($fullDir);
        foreach ($files as $file) {
            if ('.' === $file || '..' === $file) continue;
            $tmp = $fullDir . DIRECTORY_SEPARATOR . $file;
            if (is_dir($tmp)) {
                $this->cleanDir($dir . DIRECTORY_SEPARATOR . $file);
            } else {
                unlink($tmp);
            }
        }
        rmdir($fullDir);
        return true;
    }
757298
public function isExtension($directory)
    {
        $returnValue = (bool) false;

        
        $hasStructure = $this->findStructureManifest($directory) !== false;
        $hasPHPManifest = false;
        
        $files = scandir($this->options['input']);
        if ($files !== false) {
        	foreach ($files as $f) {
				if (is_file($this->options['input'] . '/' .$f) && is_readable($this->options['input'] . '/' . $f)) {
					if ($f == 'manifest.php') {
						$hasPHPManifest = true;
					}
				}
        	}
        }
        
        $returnValue = $hasStructure || $hasPHPManifest;
        

        return (bool) $returnValue;
    }
574619
private function ensureDirectoryIsSafe($directory)
    {
        if (
            $directory === '..'
            || strpos($directory, '../') !== false
            || strpos($directory, '/..') !== false
        ) {
            throw new \InvalidArgumentException("File path must not contain ..");
        }
    }
384062
public function dirExists($dir)
    {
        return ($this->isConnected() === true) ? ftp_rmdir($this->connectionString.$dir) : false;
    }
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;
    }
974946
public function emptyDir($directory)
    {
        [$fs, $directory] = $this->getFilesystemAndPath($directory);

        $fs->emptyDir($directory);
    }
1280902
public static function delDir($dir) {
        $all = self::readDir($dir, self::ALL, true, NULL);
        if (isset($all['files'])) {
            foreach ($all['files'] as $file) {
                if (is_array($file)) {
                    foreach ($file as $fil) {
                        if (!unlink($fil)) {
                            return false;
                        }
                    }
                } else {
                    if (!unlink($file)) {
                        return false;
                    }
                }
            }
        }

        if (isset($all['dirs'])) {
            foreach (array_reverse($all['dirs']) as $_dir) {
                if (is_array($_dir)) {
                    foreach ($_dir as $_dr) {
                        if (!rmdir($_dr)) {
                            return false;
                        }
                    }
                } else {
                    if (!rmdir($_dir)) {
                        return false;
                    }
                }
            }
        }

        return rmdir($dir);
    }
59005
public static function isEmptyDir($dir)
    {
        $handle = opendir($dir);
        if($handle){
            $item = readdir($handle);
            while($item){
                if ($item != "." && $item != ".."){
                    @closedir($handle);
                    return false;
                }
                $item = readdir($handle);
            }
        }
        return true;
    }
394237
public function directories($directory)
    {
        $directories = [];

        foreach (Finder::create()->in($directory)->directories()->depth(0)->sortByName() as $dir) {
            $directories[] = $dir->getPathname();
        }

        return $directories;
    }
675345
protected function makeDir($directory)
    {
        if (!$this->filesystem->isDirectory($directory)) {
            $this->filesystem->makeDirectory($directory, 0777, true);
        }
    }
1283569
protected function normalizeDirectory($directory)
    {
        $last = $directory[strlen($directory) - 1];
        if (in_array($last, array('/', '\\'))) {
            $directory[strlen($directory) - 1] = DIRECTORY_SEPARATOR;
            return $directory;
        }
        $directory .= DIRECTORY_SEPARATOR;
        return $directory;
    }
82817
public static function rmDir($dir)
    {
        if (!file_exists($dir)) {
            return true;
        }
        if (!is_dir($dir)) {
            return unlink($dir);
        }
        foreach (scandir($dir) as $item) {
            if ($item == '.' || $item == '..') {
                continue;
            }
            if (!Paths::rmDir($dir . DIRECTORY_SEPARATOR . $item)) {
                return false;
            }

        }
        return rmdir($dir);
    }