Get folders of specified directory

@param string $dir
@param boolean $recursive
@return string[]
17999
static public function getFolders( $dir, $recursive = false )
    {
        $subDirs = [];
        if ( ( $dh = opendir( $dir ) ) ) {
            while ( ( $file = readdir( $dh ) ) !== false ) {
                if ( $file !== '.' && $file !== '..' && is_dir( $dir . '/' . $file ) ) {
                    $subDirs[] = $file;
                    if ( $recursive ) {
                        $subDirs = array_merge( $subDirs, self::getFolders( $dir . DS . $file, true ) );
                    }
                }
            }
            closedir( $dh );
        }
        return $subDirs;
    }
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;
	}
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;
    }
226974
public function listContents($path = '/', $recursive = false)
    {
        $contents = $this->getApi()->getTreeMetadata($path, $recursive);

        if ($this->isDirectoryContents($contents) === false) {
            $contents = [];
        }

        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;

   }
84976
public function listContents($directory = '', $recursive = false)
	{
		$contents = parent::listContents($directory, $recursive);

		return $this->encapsulate($contents);
	}
116529
public static function list_files($dir, $dirfile = false, $md5 = true, $root = true)
    {
        static $return = [];
        if ($root) {
            $return = [];
        }
        $filepoint = opendir($dir);
        while (($target = readdir($filepoint)) !== false) {
            if ("." == $target || ".." == $target) {
                continue;
            }
            if (is_dir($dir . $target)) {
                self::list_files($dir . $target . '/', $dirfile, $md5, false);
            } else {
                if ($md5) {
                    $file = $dirfile ? $dir . $target : $target;
                    $return[md5_file($dir . $target)] = $file;
                } else {
                    $file = $dirfile ? $dir . $target : $target;
                    $return[] = $file;
                }
            }
        }
        closedir($filepoint);
        return $return;
    }
1119465
public function listContents($directory = '', $recursive = false)
    {
        [$filesystem, $directory, $prefix] = $this->getFilesystemAndPath($directory);
        $result = $filesystem->listContents($directory, $recursive);

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

        return $result;
    }
492542
public function listContents($directory = '', $recursive = false)
    {
        $list = [];

        $response = $this->listObjects($directory, $recursive);

        foreach ((array) $response->get('Contents') as $content) {
            $list[] = $this->normalizeFileInfo($content);
        }

        return $list;
    }
45547
public function files($directory)
    {
        $directory = ltrim($directory, "/");
        $files = array();

        $dirIterator = new RecursiveDirectoryIterator($this->pathRoot.$directory);
        $iterator = new RecursiveIteratorIterator($dirIterator, RecursiveIteratorIterator::CHILD_FIRST);
        
        foreach ($iterator as $file) {
            if (filetype($file) == 'file') {
                $files[] = strval($file);
            }
        }
        
        return $files;
    }
410450
static public function rmdir($dir, $recursive = false)
    {
        $dir = realpath($dir);
        if (!is_dir($dir)) return true;
        if (true !== $recursive) return @rmdir($dir);
        $dp = @opendir($dir);
        while ($file = @readdir($dp)) {
            if ('.' === $file || '..' === $file) continue;
            $cur_file = $dir . '/' . $file;
            if (is_dir($cur_file)) {
                self::rmdir($cur_file, true);
            } elseif (is_file($cur_file)) {
                @unlink($cur_file);
            }
        }
        @closedir($dp);
        return @rmdir($dir);
    }
955985
protected function listDirectoryContents($directory, $recursive = true)
    {
        $result = [];
        $connection = $this->getConnection();
        $location = $this->prefix($directory);
        $listing = $connection->rawlist($location);

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

        foreach ($listing as $filename => $object) {
            if (in_array($filename, ['.', '..'])) {
                continue;
            }

            $path = empty($directory) ? $filename : ($directory.'/'.$filename);
            $result[] = $this->normalizeListingObject($path, $object);

            if ($recursive && isset($object['type']) && $object['type'] === NET_SFTP_TYPE_DIRECTORY) {
                $result = array_merge($result, $this->listDirectoryContents($path));
            }
        }

        return $result;
    }
344015
public function listContents($directory = '', $recursive = false)
    {
        return $this->normalizeResponse(
            Cosapi::listFolder($this->getBucket(), $directory)
        );
    }
433093
private function getFiles($directory)
    {
        $fileList = [];
        $files = scandir($directory);
        $this->log(sprintf("Scanning dir %s, found %d files", $directory, count($files)));
        foreach ($files as $index => $file) {
            // recursive retrieve files in subdirectories
            if (true === is_dir($directory . DIRECTORY_SEPARATOR . $file) && !in_array($file, [".", ".."])) {
                $fileList = array_merge(
                    $fileList,
                    $this->getFiles($directory . DIRECTORY_SEPARATOR . $file)
                );
                continue;
            }

            // not the file we want
            if (false === $this->isRequiredFile($file)) {
                $this->log(sprintf("Files %s is not required", $directory . DIRECTORY_SEPARATOR . $file));
                continue;
            }
            $this->log(sprintf("Collected %s", $directory . DIRECTORY_SEPARATOR . $file));
            $fileList[] = $directory . DIRECTORY_SEPARATOR . $file;
        }
        return $fileList;
    }
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;
    }
698617
public function getFolders($recursive = false)
    {
        return $this->appendIterator(
            function ($path) use ($recursive) {
                return Filesystem::folders((string) $path, $recursive);
            }
        );
    }
373477
public function listDirectory($directory, $recursive = false)
    {
        $results = $this->scanDirectory($directory, $recursive);

        if (false === $results) {
            throw new \RuntimeException(sprintf(
                'Unable to list directory "%s", maybe it is not a directory '.
                'or it does not exist.',
                $directory
            ));
        }

        return array(
            'files'       => $results[0],
            'directories' => $results[1]
        );
    }