The directory to analyze.

This function returns an array representation of the directory structure, including any
files and nested directories that might exist.

@param  $directory

@return array
@throws InvalidPathException
181702
public function analyze($directory)
    {
        if (!$this->fileSystem->exists($directory) || !$this->fileSystem->isDirectory($directory)) {
            throw new InvalidPathException($directory . ' is not a valid directory.');
        }

        $structure = $this->fileSystem->allFiles($directory);

        $newStructure = [];

        foreach ($structure as $path) {
            $type = ($this->fileSystem->isFile($path)) ? 'file' : 'dir';
            $newStructure[] = [
                'path' => $this->normalizePath($path->getRelativePathName()),
                'type' => $type,
                'origin' => $this->normalizePath($path->getRealPath()),
                'home' => $this->normalizePath(substr($path->getRealPath(), 0, (-1 * strlen($path->getRelativePathName()))))
            ];
        }

        return $newStructure;
    }
843758
public function moveToDirectory($directory)
    {
        $targetPath = rtrim($directory, '/') . '/' . $this->getClientFilename();

        return $this->moveTo($targetPath);
    }
220138
protected function createFileLocator($directory)
    {
        if (!is_dir($directory) || !is_readable($directory)) {
            throw new \InvalidArgumentException(sprintf('Could not create procedure loader as directory does not exist or is not readable: "%s"', $directory));
        }

        return new FileLocator($directory);
    }
590969
public function getDir($directory)
    {
        $directory = str_replace('/', DS, $directory);
        if (strpos($directory, $this->getBaseDir()) === false || !file_exists($directory)) {
            $directory = $this->getBaseDir() . DS . ltrim($directory, DS);
        }
        return $directory;
    }
607129
public function rm(string $directory): bool {
    if (is_dir($directory)) {
      foreach (new DirectoryIterator(Path::replaceOSSeparator($directory)) as $fileInfo) {
        if (!$fileInfo->isDot()) {
          if ($fileInfo->isDir()) {
            $this->rm($fileInfo->getPathname());
            @rmdir($fileInfo->getPathname());
          } else if ($fileInfo->isFile()) {
            @unlink($fileInfo->getPathname());
          }
        }
      }
      @rmdir($directory);
    }
    return !file_exists($directory);
  }
1283569
protected function normalizeDirectory($directory)
    {
        $last = $directory[strlen($directory) - 1];
        if (in_array($last, array('/', '\\'))) {
            $directory[strlen($directory) - 1] = DIRECTORY_SEPARATOR;
            return $directory;
        }
        $directory .= DIRECTORY_SEPARATOR;
        return $directory;
    }
507333
public function listDirectory($directory = '.', $ref = 'HEAD')
    {
        $directory  = FileSystem::normalizeDirectorySeparator($directory);
        $directory  = $this->resolveLocalPath(rtrim($directory, '/') . '/');
        $path       = $this->getRepositoryPath();

        /** @var $result CallResult */
        $result = $this->getGit()->{'ls-tree'}($path, array(
            '--name-only',
            '--full-name',
            '-z',
            $ref,
            $this->translatePathspec($directory)
        ));
        $result->assertSuccess(sprintf('Cannot list directory "%s" at "%s" from "%s"',
            $directory, $ref, $this->getRepositoryPath()
        ));

        $output     = $result->getStdOut();
        $listing    = array_map(function($f) use ($directory) {
            return str_replace($directory, '', trim($f));
        }, explode("\x0", $output));
        return $listing;
    }
520479
public function items($directory)
    {
        $items = array();

        $metadata = $this->dropbox->getMetadata($this->pathRoot.$directory);

        if (isset($metadata['contents']) && is_array($metadata['contents']))
        {
            foreach ($metadata['contents'] as $file)
            {
                if ($file['is_dir'] == false) {
                    $items[] = $file['path'];
                }
            }
        }

        return $items;
    }
1133336
protected function findCommandsFiles($directory)
    {
        $glob = glob($directory.'/*');

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

        // To get the appropriate files, we'll simply glob the directory and filter
        // out any "files" that are not truly files so we do not end up with any
        // directories in our list, but only true files within the directory.
        return array_filter($glob, function ($file) {
            return filetype($file) == 'file';
        });
    }
438907
public function isDirectory($directory)
	{
		$directory = Util::normalizePath($directory);

		return (bool) $this->adapter->isDirectory($directory);
	}
489158
public function directories($directory, $pattern = '*')
    {
        $files = $this->formatDirsAndFiles($this->laravelFS->directories($directory));

        return $this->filterPaths($files, $pattern, []);
    }
1305834
static function contents($directory) {
        if (!self::exists($directory)) return null;

        $dircontents = [];

        $contents = scandir($directory);

        foreach ($contents as $content) {
            if ($content != '.' && $content != '..') {
                array_push($dircontents, $content);
            }
        }

        return $dircontents;
    }
1249478
public function getDirs($dir)
    {
        $dirArr = array();
        $files = ftp_rawlist($this->link, $dir);
        foreach ($files as $v) {
            $file = ltrim(strrchr($v, ' '), ' ');
            $path = "{$dir}/{$file}";
            if (preg_match('/^d/', $v)) {
                if (in_array($file, array('.', '..'))) {
                    continue;
                }
                if (preg_match('/^[a-zA-z0-9]+$/', $file)) { //file check
                    $dirArr[] = $path;
                    $dirArr = array_merge($dirArr, self::getDirs($path));
                }
            }
        }
        return $dirArr;
    }
434417
private function listObjects($directory = '', $recursive = false)
    {
        return $this->client->listObjects([
            'Bucket'    => $this->getBucket(),
            'Prefix'    => ((string) $directory === '') ? '' : ($directory.'/'),
            'Delimiter' => $recursive ? '' : '/',
        ]);
    }
91131
public static function findDirs(string $path): array
    {
        $result = [];

        try {
            static::validatePath($path);
            $path = new DirectoryIterator($path);
        } catch (InvalidArgumentException $e) {
            return $result;
        } catch (UnexpectedValueException $e) {
            return $result;
        }

        foreach ($path as $dir) {
            if ($dir->isDot()) {
                continue;
            }
            if (!$dir->isDir()) {
                continue;
            }
            $result[] = $dir->getFilename();
        }
        asort($result);

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

        return $this->filterPaths($all, $pattern);
    }
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;
    }