List all files in the directory.

@param string $path
@param bool   $recursive

@return array
191818
public function listFiles(string $path = '', bool $recursive = false)
    {
        $contents = $this->listContents($path, $recursive);

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

        return \array_values(\array_filter($contents, $filter));
    }
198756
public static function getFileList( $path, $pattern = NULL )
	{
		$index	= new FS_Folder_RecursiveLister( $path );
		$index->setPattern( $pattern );
		$index->showFiles( TRUE );
		$index->showFolders( FALSE );
		return $index->getList();
	}
1370590
public function listFolder(string $path, bool $recursive = false) : array
	{
		$path = $this->normalizePath($path);
			
		$requestUrl = $this->siteUrl.'/sites/'.$this->siteName.'/_api/Web/GetFolderByServerRelativeUrl(\''.$this->folderPath.$path.'\')/Folders';
		
		$options = [
			'headers' => $this->requestHeaders,
		];
			
		$response = $this->send('GET', $requestUrl, $options);
			
		$folders = json_decode($response->getBody())->d ?? ['results' => []];
			
		// Making sure we convert the object to an array
		if (!is_array($folders)) {
			$folders = json_decode(json_encode($folders), true);
		}
			
		return $folders['results'];
	}
20457
public function listContents($directory = '', $recursive = false)
    {
        $directory = rtrim($directory, '\\/');

        $result = [];
        $nextMarker = '';
        while (true) {
            // max-keys 用于限定此次返回object的最大数，如果不设定，默认为100，max-keys取值不能大于1000。
            // prefix   限定返回的object key必须以prefix作为前缀。注意使用prefix查询时，返回的key中仍会包含prefix。
            // delimiter是一个用于对Object名字进行分组的字符。所有名字包含指定的前缀且第一次出现delimiter字符之间的object作为一组元素
            // marker   用户设定结果从marker之后按字母排序的第一个开始返回。
            $options = [
                'max-keys' => 1000,
                'prefix' => $directory . '/',
                'delimiter' => '/',
                'marker' => $nextMarker,
            ];
            $res = $this->ossClient->listObjects($this->bucket, $options);

            // 得到nextMarker，从上一次$res读到的最后一个文件的下一个文件开始继续获取文件列表
            $nextMarker = $res->getNextMarker();
            $prefixList = $res->getPrefixList(); // 目录列表
            $objectList = $res->getObjectList(); // 文件列表
            if ($prefixList) {
                foreach ($prefixList as $value) {
                    $result[] = [
                        'type' => 'dir',
                        'path' => $value->getPrefix()
                    ];
                    if ($recursive) {
                        $result = array_merge($result, $this->listContents($value->getPrefix(), $recursive));
                    }
                }
            }
            if ($objectList) {
                foreach ($objectList as $value) {
                    if (($value->getSize() === 0) && ($value->getKey() === $directory . '/')) {
                        continue;
                    }
                    $result[] = [
                        'type' => 'file',
                        'path' => $value->getKey(),
                        'timestamp' => strtotime($value->getLastModified()),
                        'size' => $value->getSize()
                    ];
                }
            }
            if ($nextMarker === '') {
                break;
            }
        }

        return $result;
    }
623938
public function listContents($dirname = '', $recursive = false)
	{
		if ($recursive) {
			throw new BadMethodCallException('Recursive listing is not yet implemented');
		}

		$keys = [];
		$cursor = $this->client->find([
			'filename' => new MongoRegex('/^' . $dirname . '/'),
		]);
		foreach ($cursor as $file) {
			$keys[] = $this->normalizeGridFSFile($file);
		}

		return Util::emulateDirectories($keys);
	}
873704
public function listSubdirs($key = '/', $recursive = false)
    {
        try {
            $data = $this->dirInfo($key, $recursive);
        } catch (EtcdException $e) {
            throw $e;
        }

        $iterator = new RecursiveArrayIterator($data);

        return $this->traversalDir($iterator);
    }
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));
    }
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;
    }
865626
public static function ListAllFiles( string $folder, bool $recursive = false ) : array
   {

      // Init the array that should contain the resulting file paths
      $files = [];

      if ( ! @\is_dir( $folder ) )
      {
         // No folder = we are done here
         return $files;
      }

      if ( ! $recursive )
      {
         // List only files directly contained inside $folder (none from sub folders)

         // Open the directory pointer
         $d = \dir( $folder );
         // Ignore . and ..
         $d->read(); $d->read();
         // loop the rest
         while ( false !== ( $entry = $d->read() ) )
         {
            $tmp = Path::Combine( $folder, $entry );
            if ( ! \is_file( $tmp ) )
            {
               // Ignore sub folders
               continue;
            }
            $files[] = $tmp;
         }
         $d->close();
         return $files;
      }

      // List all files, also from sub folders
      static::_listRecursive( $files, $folder );

      return $files;

   }
121139
public function listContents(string $directory = '', bool $recursive = false): array
    {
        list($prefix, $directory) = $this->getPrefixAndPath($directory);

        $fs     = $this->getFileSystem($prefix);
        $list   = $fs->listContents($directory, $recursive);

        foreach ($list as &$file) {
            $file['filesystem'] = $prefix;
        }

        unset($prefix, $directory, $fs);

        return $list;
    }
172487
protected function getSchemas($directory, $recursive = false)
    {
        $finder = new Finder();
        $finder
            ->name('*schema.xml')
            ->sortByName()
            ->in($directory);
        if (!$recursive) {
            $finder->depth(0);
        }

        return iterator_to_array($finder->files());
    }
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;
    }
1313416
public static function files($path, $recursive = false, $toArray = false, $pathType = self::PATH_ABSOLUTE)
	{
		/**
		 * Files callback
		 *
		 * @param \SplFileInfo                $current  Current item's value
		 * @param string                      $key      Current item's key
		 * @param \RecursiveDirectoryIterator $iterator Iterator being filtered
		 *
		 * @return boolean   TRUE to accept the current item, FALSE otherwise
		 */
		$callback = function ($current, $key, $iterator) {
			return $current->isFile();
		};

		$files = static::findByCallback($path, $callback, $recursive);
		
		if ($toArray) {
		    $files = static::toArray($files, $pathType);
		}
		
		return $files;
	}
84976
public function listContents($directory = '', $recursive = false)
	{
		$contents = parent::listContents($directory, $recursive);

		return $this->encapsulate($contents);
	}
327749
public static function dirs($path, $recursive = false, $toArray = false, $pathType = self::PATH_ABSOLUTE)
	{
		/**
		 * Files callback
		 *
		 * @param \SplFileInfo                $current  Current item's value
		 * @param string                      $key      Current item's key
		 * @param \RecursiveDirectoryIterator $iterator Iterator being filtered
		 *
		 * @return boolean   TRUE to accept the current item, FALSE otherwise
		 */
		$callback = function ($current, $key, $iterator) use ($path, $recursive)
		{
			if ($recursive)
			{
				// Ignore self
				if ($iterator->getRealPath() == static::cleanPath($path))
				{
					return false;
				}

				// If set to recursive, every returned folder name will include a dot (.),
				// so we can't using isDot() to detect folder.
				return $iterator->isDir() && ($iterator->getBasename() != '..');
			}
			else
			{
				return $iterator->isDir() && !$iterator->isDot();
			}
		};

		$files = static::findByCallback($path, $callback, $recursive);
		
		if ($toArray) {
		    $files = static::toArray($files, $pathType);
		}
	    
	    return $files;
	}
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;
	}
434417
private function listObjects($directory = '', $recursive = false)
    {
        return $this->client->listObjects([
            'Bucket'    => $this->getBucket(),
            'Prefix'    => ((string) $directory === '') ? '' : ($directory.'/'),
            'Delimiter' => $recursive ? '' : '/',
        ]);
    }