Return all directories in $directory. Optionally filter by $pattern.

@param string $directory
@param string $pattern (optional)

@return array
489158
public function directories($directory, $pattern = '*')
    {
        $files = $this->formatDirsAndFiles($this->laravelFS->directories($directory));

        return $this->filterPaths($files, $pattern, []);
    }
1153734
protected function getFileIterator($path, $pattern = '/^.+\.php$/')
    {
        if (is_dir($path)) {
            return new \RegexIterator(new \DirectoryIterator($path), $pattern, \RegexIterator::GET_MATCH);
        }
        if (is_file($path) && 1 === preg_match($pattern, $path)) {
            return [new \SplFileInfo($path)];
        }
        return [];
    }
615614
protected function getFilesByPattern($pattern)
    {
        $iterator = Injector::inst()->create('GreenFinder')
            ->in($this->getPath())
            ->name($pattern);
        $files = [];

        foreach ($iterator as $file) {
            $files[] = $this->getRelativePath() . '/' . $file->getRelativePathname();
        }

        return $files;
    }
852972
public function GetFiles($pattern = "")
	{
		$files = Array();
		$dh = opendir($this->Path);

		while ($fname = readdir($dh)) 
		{
			if (is_file($this->Path.$fname))
			{
				if ($pattern == "" || preg_match($pattern,$fname) > 0)
				{
					$files[] = new FileHelper($this->Path.$fname);
				}
			}
		}
		
		closedir($dh);
	    
		return $files;
	}
467749
public function rsearch($folder, $pattern)
    {
        $dir      = new RecursiveDirectoryIterator($folder);
        $iterator = new RecursiveIteratorIterator($dir);
        $files    = new RegexIterator($iterator, $pattern, RegexIterator::GET_MATCH);
        $fileList = [];

        foreach ($files as $file) {
            $fileList = array_merge($fileList, $file);
        }

        return $fileList;
    }
667278
public function directories($directory = null, $recursive = false)
    {

        $directories = [ ];

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

        return $directories;
    }
127212
private function getDirectory($kernelRootDir, $pattern)
    {
        $firstCharacter = substr($pattern, 0, 1);
        if ('/' === $firstCharacter || DIRECTORY_SEPARATOR === $firstCharacter) {
            return $pattern;
        }

        return $kernelRootDir.DIRECTORY_SEPARATOR.$pattern;
    }
498293
public function directories($directory = null, $recursive = false)
    {
        $contents = $this->driver->listContents($directory, $recursive);

        return $this->filterContentsByType($contents, 'dir');
    }
375494
protected function rglob($directory, $pattern, $ltrim = null)
	{
		$iterator = new RegexIterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory, FilesystemIterator::SKIP_DOTS)), $pattern);
		$offset = strlen($ltrim);
		$files = array();

		foreach($iterator as $file)
			$files[] = substr($file->getPathname(), $offset);

		return $files;
	}
209932
public static function dirList($dir) {
        if (!is_dir($dir))
            throw new \Exception('"' . $dir . '" is not a valid directory');

        $l = array();
        foreach (self::cleanScandir($dir) as $f) {
            if (is_dir($dir . $f)) {
                $l[] = $dir . $f . '/';
                $l = array_merge($l, self::dirList($dir . $f . DIRECTORY_SEPARATOR));
            }
        }
        return $l;
    }
128873
public function findClasses($directory)
    {
        $classes = [];
        foreach (Finder::create()->in($directory)->name('*.php') as $file) {
            $classes[] = $this->findClass($file->getRealPath());
        }
        return array_filter($classes);
    }
859752
public function listContents($directory = '', $recursive = false)
    {
        try{
            //组合目录
            $directory  = static::normalizerPath($directory);

            $file_list = $this->getUpyun()->getList($directory);

            if (is_array($file_list) && count($file_list) > 0 ) {
                foreach ($file_list as &$file) {
                    $file['path']   = static::normalizerPath($directory) . DIRECTORY_SEPARATOR . $file['name'];
                }
            }
            return $file_list;
        }catch (Exception $e){

        }
        return [];
    }
358669
protected static function get_file_list($directory) {
        global $CFG;
        $directoryroot = $CFG->dirroot;
        $finalfiles = array();
        if (is_dir($directory)) {
            if ($handle = opendir($directory)) {
                $files = scandir($directory);
                foreach ($files as $file) {
                    if ($file != '.' && $file != '..') {
                        // Ignore the file if it is external to the system.
                        if (strrpos($directory, $directoryroot) !== false) {
                            $location = substr($directory, strlen($directoryroot));
                            $name = substr($file, 0, -4);
                            $finalfiles[$name] = $location  . '/' . $file;
                        }
                    }
                }
            }
        }
        return $finalfiles;
    }
637461
public function items($directory)
    {
        $directory = trim($directory, '/') . '/';

        $options = array(
            'return_prefixes' => true,
            'sort_results' => true
        );

        $objectIterator = $this->clientS3->getIterator('ListObjects', array(
            'Bucket'    => $this->bucket,
            'Prefix'    => $directory,
            'Delimiter' => '/',
        ), $options);

        $iterator = new CallbackFilterIterator($objectIterator, function($object){
            return (isset($object['Key']) || isset($object['Prefix']));
        });

        $files = array();

        foreach ($iterator as $object)
        {
            $files[] = isset($object['Key']) ? $object['Key'] : $object['Prefix'];
        }

        return $files;
    }
1029538
private static function getLeadingDir(string $pattern): string
  {
    $dir = $pattern;

    $pos = strpos($dir, '*');
    if ($pos!==false) $dir = substr($dir, 0, $pos);

    $pos = strpos($dir, '?');
    if ($pos!==false) $dir = substr($dir, 0, $pos);

    $pos = strrpos($dir, '/');
    if ($pos!==false)
    {
      $dir = substr($dir, 0, $pos);
    }
    else
    {
      $dir = '.';
    }

    return $dir;
  }
1133336
protected function findCommandsFiles($directory)
    {
        $glob = glob($directory.'/*');

        if ($glob === false) {
            return [];
        }

        // To get the appropriate files, we'll simply glob the directory and filter
        // out any "files" that are not truly files so we do not end up with any
        // directories in our list, but only true files within the directory.
        return array_filter($glob, function ($file) {
            return filetype($file) == 'file';
        });
    }
1032093
public function scan($directory = GC_DIR_MODULE)
    {
        $modules = array();

        foreach (scandir($directory) as $module_id) {

            if (!$this->isValidId($module_id)) {
                continue;
            }

            $info = $this->getInfo($module_id);

            if (!isset($info['core'])) {
                continue;
            }

            $modules[$module_id] = $info;
        }

        return $modules;
    }