List the contents of a directory.

@param string $directory
@param bool   $recursive

@return array
547170
protected function listDirectoryContents($directory, $recursive = true)
	{
		$result = [
			[]
		];
		$connection = $this->getConnection();
		$location = $this->prefix($directory);

		if (!$stream = @\ssh2_exec($connection, "ls {$location}")) {
			return [];
		}

		\stream_set_blocking($stream, true);
		$cmd = \fread($stream, 4096);
		$listing = \explode("\n", $cmd);

		foreach ($listing as $filename) {
			if (\in_array($filename, ['.', '..'], true)) {
				continue;
			}

			$path = empty($directory) ? $filename : ($directory . '/' . $filename);
			$stat = $this->getMetadata($path);
			$result[0][] = $stat;

			if ($recursive && $stat['type'] === 'dir') {
				$result[] = $this->listDirectoryContents($path);
			}
		}

		return !isset($result[1]) ? $result[0] : \array_merge(...$result);
	}
373576
public function scanDir($directory = '.', $recursive = false)
    {
        return $this->parseRawList($this->rawlist($directory, $recursive));
    }
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);
    }
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;
    }
1314554
public function listContents($directory = '', $recursive = false) {
			try {
				$files = $this->bucket->listFileNames(['prefix' => $directory]);
				$returnFiles = [];
				foreach ($files as $file) {
					$returnFiles[] = $this->normalizeFileInfo($file);
				}
				
				return $returnFiles;
			} catch (\Exception $e) {
				throw new B2FlysystemException('Error retrieving files', B2FlysystemException::B2_SDK_ERROR, $e);
			}
		}
578052
public function dirInfo($key = '/', $recursive = false)
    {
        $query = [];
        if ($recursive === true) {
            $query['recursive'] = 'true';
        }

        return $this->httpGet($this->getKeyUrl($key), $query);
    }
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());
    }
84976
public function listContents($directory = '', $recursive = false)
	{
		$contents = parent::listContents($directory, $recursive);

		return $this->encapsulate($contents);
	}
621237
public function listDirectory($directory = '')
    {
        $this->ensureDirectoryExists($this->directory, $this->create);

        $directory = preg_replace('/^[\/]*([^\/].*)$/', '/$1', $directory);

        $items = $this->parseRawlist(
            ftp_rawlist($this->getConnection(), '-al '.$this->directory.$directory) ?: array()
        );

        $fileData = $dirs = array();
        foreach ($items as $itemData) {
            if ('..' === $itemData['name'] || '.' === $itemData['name']) {
                continue;
            }

            $item = array(
                'name' => $itemData['name'],
                'path' => trim(($directory ? $directory.'/' : '').$itemData['name'], '/'),
                'time' => $itemData['time'],
                'size' => $itemData['size'],
            );

            if ('-' === substr($itemData['perms'], 0, 1)) {
                $fileData[$item['path']] = $item;
            } elseif ('d' === substr($itemData['perms'], 0, 1)) {
                $dirs[] = $item['path'];
            }
        }

        $this->fileData = array_merge($fileData, $this->fileData);

        return array(
           'keys' => array_keys($fileData),
           'dirs' => $dirs,
        );
    }
810981
public function listFiles($directory)
    {
        if (!file_exists($directory)) {
            return collect([]);
        }

        return $this->scanDir($directory)->reject(function ($item) {
            return !$this->isAllowedDirectory($item) && !$this->isYamlFile($item);
        })->mapWithKeys(function ($item) {
            if (is_dir($item)) {
                return [basename($item) => $this->listFiles($item)->toArray()];
            }

            return [$this->cleanKey($item) => $item];
        });
    }
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);
    }
269504
public function ls($key = '/', $recursive = false)
    {
        $this->values = array();
        $this->dirs = array();

        try {
            $data = $this->listDir($key, $recursive);
        } catch (EtcdException $e) {
            throw $e;
        }

        $iterator = new RecursiveArrayIterator($data);
        return $this->traversalDir($iterator);
    }
1327016
public function listFiles($directory)
    {
        $writeBinn= new BinnList;

        $writeBinn->addUint8(self::FSERV_READDIR);
        $writeBinn->addStr($directory);     // Dir path
        $writeBinn->addUint8(0);       // Mode

        $read = $this->writeAndReadSocket($writeBinn->serialize());

        $readBinn = new BinnList;

        $readBinn->binnOpen($read);
        $results = $readBinn->unserialize();

        if ($results[0] != self::FSERV_STATUS_OK) {
            // Error
            throw new RuntimeException('GDaemon List files error:' . isset($results[1]) ? $results[1] : 'Unknown');
        }

        $filesList = $results[2];
        $returnList = [];

        foreach($filesList as &$file) {

            if (in_array(basename($file[0]), ['.', '..'])) {
                continue;
            }

            $returnList[] = basename($file[0]);
        }

        return $returnList;
    }
1295238
public static function directoryToArray($directory, $recursive = FALSE, $extension = NULL) {
    $array_items = array();
    if ($handle = opendir($directory)) {
      while (FALSE !== ($file = readdir($handle))) {
        if ($file != "." && $file != ".." && (empty($extension) ||
            (!empty($extension) && substr($file, -strlen($extension)) === $extension))
        ) {

          if (is_dir($directory . "/" . $file)) {
            if ($recursive) {
              $array_items = array_merge($array_items, self::directoryToArray($directory . "/" . $file, $recursive));
            }
          }
          else {
            $file = $directory . "/" . $file;
            $array_items[] = preg_replace("/\/\//si", "/", $file);
          }
        }
      }
      closedir($handle);
    }
    return $array_items;
  }
691664
private function recursiveSearch($directory)
    {
        
		if (is_dir($directory)) {
	    	// We get the list of files and directories.
	    	if (($files = scandir($directory)) !== false) {
	    		
	    		foreach($files as $fd) {
	
	   		 		if (!preg_match("/^\./", $fd) &&  $fd != "ext") {
	   		 			// If it is a directory ...
	   		 			if (is_dir($directory . $fd. "/")) {
	   		 				$this->recursiveSearch($directory . $fd . "/");
		    			// If it is a file ...
	    				} else {
	    					// Retrieve from the file ...
	    					$this->getTranslationsInFile($directory . $fd);
	    				}
	   		 		}
	    			
	    		}
	    	}   	
		}
		
        
    }
226974
public function listContents($path = '/', $recursive = false)
    {
        $contents = $this->getApi()->getTreeMetadata($path, $recursive);

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

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

        return $this->filterContentsByType($contents, 'dir');
    }