List directory content

@access public

@param  array $exclude
@param  bool  $recursive

@return array
976684
public function scan($c = true, &$list = array(), $exclude_extension = array(), $exclude_file = array(), $exclude_dir = array(), $dir = "")
    {
        if (is_array($c)) {
            foreach ($c as $key => $item) {
                ${$key} = $item;
            }
        } else {
            $recursive = $c;
        }

        if (!$exclude_extension) $exclude_extension = $this->_exclude_extension;
        if (!$exclude_file) $exclude_file = $this->_exclude_file;
        if (!$exclude_dir) $exclude_dir = $this->_exclude_dir;

        // Lowercase exclude Arr
        $exclude_extension = array_map("strtolower", $exclude_extension);
        $exclude_file = array_map("strtolower", $exclude_file);
        $exclude_dir = array_map("strtolower", $exclude_dir);

        $dir = ($dir == "") ? $this->_path : $dir;
        if (substr($dir, -1) != DS) $dir .= DS;

        // Open the folder
        $dir_handle = @opendir($dir) or die("Unable to open $dir");

        // Loop through the files
        while ($file = readdir($dir_handle)) {

            // Strip dir pointers and extension exclude
            $extension = $this->getExtension($file);
            if ($file == "." || $file == ".." || in_array($extension, $exclude_extension)) continue;

            if (is_dir($dir . $file)) {
                if (!in_array(strtolower($file), $exclude_dir)) {
                    $info = "";
                    $info["type"] = "dir";
                    $info["path"] = $dir;
                    $info["fullpath"] = $dir . $file;
                    $info["urlpath"] = str_replace(Config::get('paths.root'), Config::get('paths.rooturl'), $info["fullpath"]);
                    $info["name"] = str_replace($dir, '', $info["fullpath"]);
                    $list[] = $info;
                }
            } else {
                if (!in_array(strtolower($file), $exclude_file)) {
                    $info = "";
                    $info["extension"] = $extension;
                    $info["type"] = "file";
                    $info["path"] = $dir;
                    $info["filename"] = $file;
                    $info["fullpath"] = $dir . $file;
                    $info["urlpath"] = str_replace(Config::get('paths.root'), Config::get('paths.rooturl'), $info["fullpath"]);
                    $info["name"] = str_replace('.' . $extension, '', $file);
                    $list[] = $info;
                }
            }

            if ($recursive && is_dir($dir . $file) && !in_array(strtolower($file), $exclude_dir)) {
                $this->scan($recursive, $list, $exclude_extension, $exclude_file, $exclude_dir, $dir . $file);
            }

        }

        // Close
        closedir($dir_handle);

        return $list;
    }
620954
public function ls($dir = '/.', $recursive = false, $ignore = array())
    {
        return $this->listItem('file', $dir, $recursive, $ignore);
    }
1301669
public function readDirectory($directory, $recursive = true)
    {
        if (is_dir($directory) === false) {
            return false;
        }

        try {
            $resource = opendir($directory);
            $contents = array();

            while (false !== ($item = readdir($resource)))
            {
                if (in_array($item, array('.', '..'))
                    || substr($item, 0, 1) == '_') {
                    continue;
                }

                $absoluteItem = $directory . DIRECTORY_SEPARATOR . $item;
                if ($recursive === true && is_dir($absoluteItem)) {
                    $contents[$item] = $this->readDirectory($absoluteItem, $recursive);
                } else {
                    $contents[$item] = $absoluteItem;
                }
            }
        } catch(\Exception $e) {
            return false;
        }

        return $contents;
    }
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);
        }
    }
292529
public function storeContents($directory, array $contents, $recursive = false)
    {
        $directories = [$directory];

        foreach ($contents as $object) {
            $this->updateObject($object['path'], $object);
            $object = $this->cache[$object['path']];

            if ($recursive && $this->pathIsInDirectory($directory, $object['path'])) {
                $directories[] = $object['dirname'];
            }
        }

        foreach (array_unique($directories) as $directory) {
            $this->setComplete($directory, $recursive);
        }

        $this->autosave();
    }
1151371
public function listContents($recursive = false)
	{
		return $this->hasAdapterOrFail()->adapter->listContents($this->getPath(), $recursive);
	}
786218
public function listFiles(bool $recursion = true): array {
		$filter = new class extends Filter {
			public function filter(File $dirOrPath): bool {
				/**
				 * @var File $dirOrPath
				 */
				return $dirOrPath->isFile();
			}
		};
		$index  = $this->addFilter($filter);
		$result = $this->listContents($recursion);
		$this->removeFilter($index);

		return $result;
	}
1059645
private function scanFolders(string $dir, bool $recursive): array
    {
        $files = [];

        // $dir comes from the database. The actual folder may not exist.
        if (is_dir($dir)) {
            foreach (scandir($dir, SCANDIR_SORT_NONE) as $path) {
                if (is_dir($dir . $path)) {
                    // What if there are user-defined subfolders “thumbs” or “watermarks”?
                    if ($path !== '.' && $path !== '..' && $path !== 'thumbs' && $path !== 'watermark' && $recursive) {
                        foreach ($this->scanFolders($dir . $path . '/', $recursive) as $subpath) {
                            $files[] = $path . '/' . $subpath;
                        }
                    }
                } else {
                    $files[] = $path;
                }
            }
        }

        return $files;
    }
1009688
protected function doRawList($dir, $recursive = false)
    {
        $connection = $this->connection;

        return $this->retry(function () use ($connection, $dir, $recursive) {
            $res = @ftp_rawlist($connection, $dir, $recursive);

            if (false === $res) {
                throw new \RuntimeException("Rawlist failed: ".$dir);
            }

            $items = array();

            foreach ($res as $child) {
                $chunks = preg_split("/\s+/", $child);
                list($item['rights'], $item['number'], $item['user'], $item['group'], $item['size'], $item['month'], $item['day'], $item['time']) = $chunks;
                $item['type'] = $chunks[0]{0}
                === 'd' ? 'directory' : 'file';
                array_splice($chunks, 0, 8);
                $item['name'] = implode(" ", $chunks);
                $item['pathname'] = \rtrim($dir, '/').'/'.$item['name'];
                $items[] = $item;
            }

            return $items;
        });
    }
536500
public function listContents($directory = '', $recursive = false): array
    {
        $result = parent::listContents($directory, $recursive);

        list(, $directory) = $this->getPrefixAndPath($directory);
        $relativePathPos = strlen(trim($directory, '/')) + 1;

        foreach ($result as &$file) {
            $file['relative_path'] = substr($file['path'], $relativePathPos);
        }

        return $result;
    }
774089
public function handle($directory = '', $recursive = false)
    {
        $contents = $this->filesystem->listContents($directory, $recursive);

        $filter = function ($object) {
            return $object['type'] === 'file';
        };

        return array_values(array_filter($contents, $filter));
    }
681704
public function addLocalDirectory($directory, $recursive = false)
    {
        if (!file_exists($directory) || !is_dir($directory)) {
            throw new Exception\InvalidArgumentException(sprintf(
                'The directory "%s" does not exists.',
                $directory
            ));
        }

        if ($recursive) {
            $iterator = new \RecursiveIteratorIterator(
                new \RecursiveDirectoryIterator($directory)
            );
        } else {
            $iterator = new \DirectoryIterator($directory);
        }

        foreach ($iterator as $fileinfo) {
            if (!$fileinfo->isFile()) {
                continue;
            }
            
            $extension = $fileinfo->getExtension();
            if ($extension != 'js') {
                continue;
            }

            $this->addLocalFile($fileinfo->getPathname());
        }

        return $this;
    }
577803
public function listDirectory($path, $recursive = false, $withHidden = true)
    {
        $dirs = $this->formatDirsAndFiles($this->laravelFS->directories($path, $recursive));
        $files = $this->formatDirsAndFiles($this->laravelFS->files($path, $recursive));

        $dirsAndFiles = $this->mergeDirsAndFiles($dirs, $files);

        return $this->formatDirsAndFiles($dirsAndFiles);
    }
420809
protected function listDirectoryContents($directory, $recursive = true)
    {
        $directory = str_replace('*', '\\*', $directory);

        if ($recursive && $this->recurseManually) {
            return $this->listDirectoryContentsRecursive($directory);
        }

        $options = $recursive ? '-alnR' : '-aln';
        $listing = $this->ftpRawlist($options, $directory);

        return $listing ? $this->normalizeListing($listing, $directory) : [];
    }
445667
public function directories($directory = null, $recursive = false)
    {
        return $this->filesystem->directories(
            $this->path($directory),
            $recursive
        );
    }
113881
public function listContents($directory = '', $recursive = false)
    {
        $bucketMgr = $this->getBucketManager();

        list($items, $marker, $error) = $bucketMgr->listFiles($this->bucket, $directory);
        if ($error !== null) {
            $this->logQiniuError($error);

            return array();
        } else {
            $contents = array();
            foreach ($items as $item) {
                $normalized = [
                    'type' => 'file',
                    'path' => $item['key'],
                    'timestamp' => $item['putTime']
                ];

                if ($normalized['type'] === 'file') {
                    $normalized['size'] = $item['fsize'];
                }

                array_push($contents, $normalized);
            }

            return $contents;
        }
    }
53967
public function listContents($directory = '', $recursive = false)
    {
        $directory  = PathLibrary::normalizerPath($directory);
        $list       = $this->getCos()->listFolder($this->getBucket(), $directory);
        $list       = json_decode($list, true);


        if ($list && $list['code'] == Response::COSAPI_SUCCESS) {

            $file_list = $list['data']['infos'];

            foreach ($file_list as &$file) {
                $file['path']   = $directory . $file['name'];
            }

            return $file_list;
        }

        return false;
    }