Get the list of directory and files that match the current partial path (or its parent directory)

@param string $partialPath

@return array

@throws \InvalidArgumentException if one of the directories does not exist
188705
public function getResultFor($partialPath)
    {
        if (file_exists($partialPath) && is_dir($partialPath)) {
            $path = $partialPath;
        } else {
            $path = dirname($partialPath);
        }

        if (!file_exists($path) || !is_dir($path) || !is_readable($path)) {
            return array();
        }

        $finder = $this->newFinder()->maxDepth(1)->in($path);

        $paths = array();
        foreach ($finder as $file) {
            /** @var SplFileInfo $file */
            $filePath = $file->getPathname();
            if ($file->isDir()) {
                $filePath .= DIRECTORY_SEPARATOR;
            }
            if (DIRECTORY_SEPARATOR === $path && DIRECTORY_SEPARATOR === $partialPath) {
                $filePath = substr($filePath, 1);
            }
            $paths[] = preg_replace('#'.preg_quote(DIRECTORY_SEPARATOR, '#').'+#', DIRECTORY_SEPARATOR, $filePath);
        }
        return $paths;
    }
678942
protected function getFileContent($path)
    {
        if (false === file_exists($path)) {
            throw new \InvalidArgumentException(sprintf('File "%s" does not exist.', $path));
        }
        
        return file_get_contents($path);
    }
342525
public static function lookupByPath($path)
    {
        if (empty($path)) {
            throw new \InvalidArgumentException('Argument "path" cannot be empty');
        }

        foreach (self::$methods_config as $key => $val) {
            if ($val['path'] === $path) {
                return $val;
            }
        }

        return null;
    }
1106914
public function getStorageBaseDirectory($basePath = null)
    {
        // Get base storage path configuration
        $storage = $this->get('storage');

        // Check if storage is relative to the application path or not
        $relative = $storage['path_is_relative'] ?: true;

        return ($relative ? $basePath . DIRECTORY_SEPARATOR : '') . $storage['base_dir'];
    }
662717
public function getLocalFileListForPath($localPath)
    {
        $files = [];
        $objects = new RecursiveIteratorIterator(
            new RecursiveDirectoryIterator($localPath),
            RecursiveIteratorIterator::LEAVES_ONLY,
            FilesystemIterator::SKIP_DOTS
        );

        /**
         * @var string $path
         * @var SplFileObject $object
         */
        foreach ($objects as $path => $object) {
            /** @noinspection TypeUnsafeComparisonInspection */
            /** @noinspection NotOptimalIfConditionsInspection */
            if ($object->getFilename() != '.' && $object->getFilename() != '..') {
                $hostTempFolderPath = $this->_config->getHostSpoolerFolderPath();

                /** @noinspection PhpMethodOrClassCallIsNotCaseSensitiveInspection */
                $remoteFilePath = str_replace($hostTempFolderPath, '/', $object->getPathName());


                /** @noinspection PhpMethodOrClassCallIsNotCaseSensitiveInspection */
                $file = [
                    'name' => $object->getFilename(),
                    'localPath' => $object->getPathName(),
                    'remotePath' => $remoteFilePath,
                    'modified' => $object->getMTime()
                ];

                $files[$object->getFilename()] = $file;
            }
        }

        return $files;
    }
1055787
public static function read(string $dir, string $includeRegEx = null, string $excludeRegEx = null):array
    {
        $files = [];
        if (!is_dir($dir)) {
            throw new \InvalidArgumentException(
                sprintf('directory "%s" is not exist.', $dir)
            );
        }
        $iterators = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir), \RecursiveIteratorIterator::SELF_FIRST);
        foreach ($iterators as $name => $file) {
            if (!$file->isDir() &&
                ($includeRegEx == null || preg_match($includeRegEx, basename($file))) &&
                ($excludeRegEx == null || !preg_match($excludeRegEx, basename($file)))
            ) {
                $files[] = $file->getRealPath();
            }
        }
        return $files;
    }
1354882
public function getFilesFromDirectories(array $directoryArray)
    {
        $directoryArray = $this->getAbsoluteDirectoryPath($directoryArray);
        if (is_array($directoryArray) && count($directoryArray)) {
            $files = array();
            foreach ($directoryArray as $directory) {
                $foundFiles = GeneralUtility::getAllFilesAndFoldersInPath(
                    array(),
                    $directory,
                    $this->indexerConfig['fileext']
                );

                if (is_array($foundFiles) && count($foundFiles)) {
                    foreach ($foundFiles as $file) {
                        $files[] = $file;
                    }
                }
            }
            return $files;
        } else {
            return array();
        }
    }
964964
public function getFullPath($path = '/')
    {
        if (mb_substr($path, 0, 1) == '/') {
            $path = mb_substr($path, 1);
        }

        $full_path = $this->getSandboxPath() . $path;

        if (strpos($full_path, '..')) {
            $full_path = realpath($full_path);

            if (mb_substr($full_path, 0, $this->sandbox_path_length) != $this->sandbox_path) {
                throw new InvalidArgumentException('$path is outside of the sanbox path');
            }
        }

        return $full_path;
    }
166181
public static function enum($dirPath)
    {
        if (!is_dir($dirPath)) {
            return new \ArrayIterator();
        }
        $iterator = new \RecursiveDirectoryIterator($dirPath, \FilesystemIterator::KEY_AS_PATHNAME | \FilesystemIterator::CURRENT_AS_FILEINFO | \FilesystemIterator::SKIP_DOTS);
        $files = new \RecursiveIteratorIterator($iterator);
        return $files;
    }
460790
protected function getSource($package, $packagePath)
    {
        $sources = [
            "{$packagePath}/{$package}/resources/config",
            "{$packagePath}/{$package}/config",
        ];

        foreach ($sources as $source) {
            $_source = str_replace('/', DIRECTORY_SEPARATOR, $source);

            if ($this->files->isDirectory($_source)) {
                return $_source;
            }
        }

        throw new InvalidArgumentException('Configuration not found.');
    }
726357
protected function loadConfigurationFile(string $configurationPath): array
    {
        $configurations = [];

        if ($configurationPath && is_dir($configurationPath)) {
            if (is_dir($configurationPath)) {
                $configurationFiles = new FilesystemIterator($configurationPath, FilesystemIterator::SKIP_DOTS);

                /** @var SplFileInfo $configurationFiles */
                foreach ($configurationFiles as $file) {
                    $configurations += $this->getConfigurationFile($file);
                }
            } else {
                if (is_file($configurationPath)) {
                    $configurations += $this->getConfigurationFile($configurationPath);
                }
            }
        }

        return $configurations;
    }
43570
protected function search_folders( $path ) {
		$return       = array();
		$base_folders = array_filter( glob( $this->trailingslashit( $path ) . '*' ), 'is_dir' );

		if ( is_array( $base_folders ) && ! empty( $base_folders ) ) {
			foreach ( $base_folders as $folder ) {
				$_sub = $this->search_folders( $this->untrailingslashit( $folder ) );

				if ( is_array( $_sub ) && ! empty( $_sub ) ) {
					$return = array_merge( $return, $_sub );
				} elseif ( is_string( $_sub ) ) {
					$return = array_merge( $return, array( $_sub ) );
					$return = array_merge( $return, array( $this->untrailingslashit( $path ) ) );
				}
			}
		} else {
			$return = array( $this->trailingslashit( $path ) );
		}

		return $return;
	}
312986
public function getPartialRootPath()
    {
        if ($this->partialRootPath === null && $this->templatePathAndFilename === null) {
            throw new Exception\InvalidTemplateResourceException('No partial root path has been specified. Use setPartialRootPath().', 1288094511);
        }
        if ($this->partialRootPath === null) {
            $this->partialRootPath = dirname($this->templatePathAndFilename) . '/Partials';
        }
        return $this->partialRootPath;
    }
922746
public function getList(string $path)
    {
        $entity = $this->getEntity($path);

        if (null !== $entity && $entity->file_exists() && $entity->is_dir()) {
            $files = [];
            $changes = $this->getChanges();
            $own = $changes->own($path);

            if (!($entity instanceof VirtualInterface)) {
                $directory = $this->getRoot();
                $directoryPath = $directory->path().'/'.$path;

                $dirHandler = opendir($directoryPath);
                if ($dirHandler) {
                    while (true) {
                        $file = readdir($dirHandler);
                        if (false === $file) {
                            break;
                        } elseif ('.' == $file || '..' == $file) {
                            continue;
                        }

                        $changesKey = ($path ? $path.'/' : '').$file;
                        if (isset($own[$changesKey])) {
                            continue;
                        }
                        $files[$changesKey] = Entity::newInstance($changesKey);
                    }
                    closedir($dirHandler);
                }
            }

            foreach ($own as $changesKey => $file) {
                /* @var $file EntityInterface */
                if ($file instanceof DeletedInterface) {
                    unset($own[$changesKey]);
                }
            }

            $mergedFiles = array_merge($files, $own);
            ksort($mergedFiles);

            $result = array_values($mergedFiles);
        } else {
            $result = null;
        }

        return $result;
    }
244268
private function getFiles($path)
    {
        $files = [];

        if (false !== $pos = strpos($path, '*')) {
            list($before, $after) = explode('*', $path, 2);
            $input = $this->fileLocator->locate($before).'*'.$after;

            if (false !== $paths = glob($input)) {
                foreach ($paths as $path) {
                    $files[] = $path;
                }
            }
        } else {
            $files = [$this->fileLocator->locate($path)];
        }

        return $files;
    }
1162284
private static function scanDfs(string $path, bool $excludeDir = true): array
    {
        $files = [];
        $subFiles = self::scanCurrentDir($path, false);

        foreach ($subFiles as $subFile) {
            $fileType = filetype($subFile);
            if ('dir' == $fileType) {
                $innerFiles = self::scanDfs($subFile, $excludeDir);
                $files = ArrayHelper::merge($files, $innerFiles);
                if (false === $excludeDir) {
                    $files[] = $subFile;
                }
            }
            if ('file' == $fileType) {
                $files[] = $subFile;
            }
        }
        return $files;
    }
947487
public function scanDirectory(string $path): array
    {
        $files = [];

        $rdi = new \RecursiveDirectoryIterator(
            $path,
            \FilesystemIterator::SKIP_DOTS |
            \FilesystemIterator::KEY_AS_FILENAME |
            \FilesystemIterator::CURRENT_AS_FILEINFO
        );

        $rii = new \RecursiveIteratorIterator($rdi);

        foreach ($rii as $fileInfo) {
            $files[] = $fileInfo;
        }

        return $files;
    }