Get list of files/directories in directory

@param string $directory
@return array
198684
public function ls($directory = null)
        {
            $list = array();

            // attempt to get list
            if($list = ftp_nlist(static::$_stream, $directory)) {
                // success
                return $list;
            // fail
            } else {
                static::$error = "Failed to get directory list";
                return array();
            }
        }
997352
public function searchDir($type, $directory = '')
    {
        $dirs = $this->search($type, $directory, 'path');
        $files = array();
        foreach ($dirs as $dir) {
            $this->_searchDirFiles($dir, $files);
        }

        return $files;
    }
1100700
public static function fromDirectory(string $directory): array
    {
        if (!\is_dir($directory)) {
            throw Exception\DirectoryDoesNotExist::fromDirectory($directory);
        }

        $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(
            $directory,
            \RecursiveDirectoryIterator::FOLLOW_SYMLINKS
        ));

        $constructs = [];

        foreach ($iterator as $fileInfo) {
            /** @var \SplFileInfo $fileInfo */
            if (!$fileInfo->isFile()) {
                continue;
            }

            if ($fileInfo->getBasename('.php') === $fileInfo->getBasename()) {
                continue;
            }

            $fileName = $fileInfo->getRealPath();

            /** @var string $source */
            $source = \file_get_contents($fileName);

            try {
                $constructsFromFile = self::fromSource($source);
            } catch (Exception\ParseError $exception) {
                throw Exception\ParseError::fromFileNameAndParseError(
                    $fileName,
                    $exception
                );
            }

            if (0 === \count($constructsFromFile)) {
                continue;
            }

            foreach ($constructsFromFile as $construct) {
                $name = $construct->name();

                if (\array_key_exists($name, $constructs)) {
                    $construct = $constructs[$name];
                }

                $constructs[$name] = $construct->definedIn($fileName);
            }
        }

        \usort($constructs, static function (Construct $a, Construct $b) {
            return \strcmp(
                $a->name(),
                $b->name()
            );
        });

        $constructsWithMultipleDefinitions = \array_filter($constructs, static function (Construct $construct) {
            return 1 < \count($construct->fileNames());
        });

        if (0 < \count($constructsWithMultipleDefinitions)) {
            throw Exception\MultipleDefinitionsFound::fromConstructs($constructsWithMultipleDefinitions);
        }

        return \array_values($constructs);
    }
1188965
public static function directory_contents($dir)
    {
        $contents = array();
        foreach(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir, \FilesystemIterator::KEY_AS_PATHNAME | \FilesystemIterator::CURRENT_AS_FILEINFO | \FilesystemIterator::SKIP_DOTS)) as $pathname => $fi) {
            $contents[] = $pathname;
        }
        natsort($contents);
        return $contents;
    }
10540
public function listContents(string $directory = '', bool $recursive = false): array
    {
        $list = [];
        $location = $this->applyBasePath($directory);

        if (! is_dir($location)) {
            return $list;
        }

        $iterator = $recursive ?
                    $this->getRecursiveDirectoryIterator($location) :
                    $this->getDirectoryIterator($location);

        foreach ($iterator as $file) {
            $path = $this->getFilePath($file);

            if (preg_match('#(^|/|\\\\)\.{1,2}$#', $path)) {
                continue;
            }

            $list[] = $this->normalizeFileInfo($file);

            unset($path);
        }

        unset($location, $iterator);

        return array_filter($list);
    }
657522
public function getFiles($dir){
		$dir = self::normalizePath($dir);
	    $files = scandir($dir);
		$results = [];
	    foreach($files as $key => $value){
		    $path = self::normalizePath(self::combinePath($dir, $value));
	        if(!is_dir($path)) {
	        	$results[] = $path;
	        } else if($value != "." && $value != "..") {
	            $results = array_merge($results, getDirContents($path));
	        }
	    }
	    return $results;
	}
956623
public static function files(\RecursiveDirectoryIterator $directory): array
    {
        if (!$directory instanceof \RecursiveDirectoryIterator) {
            $directory = new \RecursiveDirectoryIterator($directory);
        }
        $files = [];
        for (; $directory->valid(); $directory->next()) {
            if ($directory->isDir() && !$directory->isDot()) {
                if ($directory->haschildren()) {
                    $files = array_merge($files, static::files($directory->getChildren()));
                };
            } else if ($directory->isFile()) {
                $files[] = $directory->getPathName();
            }
        }
        return $files;
    }
667278
public function directories($directory = null, $recursive = false)
    {

        $directories = [ ];

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

        return $directories;
    }
1118700
public function all($directory = '/')
    {
        $directories = $this->directories($directory)->transform(function ($item) {
            return $item + ['type' => self::MEDIA_TYPE_DIRECTORY];
        });

        $files = $this->files($directory)->transform(function (array $item) {
            return $item + ['type' => self::MEDIA_TYPE_FILE];
        });

        return array_merge($directories->toArray(), $files->toArray());
    }
55781
protected function listDirectoryContentsRecursive($directory)
    {
        $listing = $this->normalizeListing($this->ftpRawlist('-aln', $directory) ?: [], $directory);
        $output = [];

        foreach ($listing as $directory) {
            $output[] = $directory;
            if ($directory['type'] !== 'dir') {
                continue;
            }

            $output = array_merge($output, $this->listDirectoryContentsRecursive($directory['path']));
        }

        return $output;
    }
1110818
protected function getDirInfo($directory)
    {
        if (! is_dir($directory)) {
            return sprintf($this->_('%s - does not exist'), $directory);
        }

        $free = disk_free_space($directory);
        $total = disk_total_space($directory);

        if ((false === $free) || (false === $total)) {
            return sprintf($this->_('%s - no disk information available'), $directory);
        }

        $percent = intval($free / $total * 100);

        return sprintf(
                $this->_('%s - %s free of %s = %d%% available'),
                $directory,
                \MUtil_File::getByteSized($free),
                \MUtil_File::getByteSized($total),
                $percent
                );
    }
898077
protected function find($directory)
    {
        if (!file_exists($directory) || !is_dir($directory) || !is_readable($directory)) {
            return false;
        }

        $iterator = new \RecursiveDirectoryIterator(realpath($directory));
        return new \RecursiveIteratorIterator($iterator);
    }
492147
protected function listFiles($disk, $directory = '', $recursive = true)
    {
        if ($recursive) {
            return $this->filesystem->disk($disk)->allFiles($directory);
        } else {
            return $this->filesystem->disk($disk)->files($directory);
        }
    }
1064163
private function getClasses($directory)
    {
        $classes = [];
        $directoryList = [];
        $includedFiles = [];

        $finder = new Finder();
        try {
            $finder->in($directory)->files()->name('*.php');
        } catch (\InvalidArgumentException $e) {
            return [[], []];
        }

        foreach ($finder as $file) {
            $directoryList[$file->getPath()] = true;
            $sourceFile = $file->getRealpath();
            if (!preg_match('(^phar:)i', $sourceFile)) {
                $sourceFile = realpath($sourceFile);
            }

            require_once $sourceFile;
            $includedFiles[$sourceFile] = true;
        }

        $declared = get_declared_classes();
        foreach ($declared as $className) {
            $reflectionClass = new \ReflectionClass($className);
            $sourceFile = $reflectionClass->getFileName();

            if ($reflectionClass->isAbstract()) {
                continue;
            }

            if (method_exists($reflectionClass, 'isAnonymous') && $reflectionClass->isAnonymous()) {
                continue;
            }

            if (isset($includedFiles[$sourceFile])) {
                $classes[$className] = true;
            }
        }

        return [array_keys($classes), $directoryList];
    }
649533
public function directories($directory, $pattern = '*')
    {
        $all = array_filter($this->listDirectory($directory), function ($path) {
            return $this->type($path) == 'dir';
        });

        return $this->filterPaths($all, $pattern);
    }
1187155
public function deleteDirectory($directory)
    {
        event(new Events\DirectoryDeleting($directory));
        $deleted = $this->disk()->deleteDirectory($directory);
        event(new Events\DirectoryDeleted($directory, $deleted));

        return $deleted;
    }
823473
public function findAll($directory): array
    {
        $cache = $this->cacheService->systemSimple();
        $key = \str_replace(['::', '\\'], '_', __METHOD__) . '_' . \crc32($directory);
        $result = $cache->get($key);
        if (!$result) {
            $result = $this->classHelper->getClassMap($directory, self::FILENAME);
            $cache->set($key, $result);
        }
        return $result;
    }