Recursively scans module override files
@param string $directory
@param array $results
@return array
435420
protected function scanOverrideFiles($directory, array &$results = array())
    {
        foreach (new DirectoryIterator($directory) as $file) {
            if ($file->isFile() && $file->getExtension() === 'php') {
                $results[] = $file->getFilename();
            } elseif ($file->isDir() && !$file->isDot()) {
                $this->scanOverrideFiles($file->getRealPath(), $results);
            }
        }

        return $results;
    }
913580
protected function listDirectoryContentsRecursive($directory)
    {
        $listing = $this->normalizeListing($this->ftpRawlist('-aln', $directory) ?: [], $directory);
        $output = [];

        foreach ($listing as $dir) {
            $output[] = [$dir];
            if ($dir['type'] !== 'dir') {
                continue;
            }

            $output[] = $this->listDirectoryContentsRecursive($dir['path']);
        }

        return \array_merge(...$output);
    }
1249296
public function find_all_files($dir) 
	{
	  $root = scandir($dir); 
    foreach($root as $value) 
    { 
        if($value === '.' || $value === '..')
        {
        	continue;
        } 
        if(is_file("$dir/$value")) 
        {
        	$result[] = "$dir/$value";
        	$this->setAsset("$dir/$value");
        	continue;
        } 
        foreach($this->find_all_files("$dir/$value") as $value) 
        { 
            $result[] = $value; 
        } 
    } 
    return $result; 
	}
1059645
private function scanFolders(string $dir, bool $recursive): array
    {
        $files = [];

        // $dir comes from the database. The actual folder may not exist.
        if (is_dir($dir)) {
            foreach (scandir($dir, SCANDIR_SORT_NONE) as $path) {
                if (is_dir($dir . $path)) {
                    // What if there are user-defined subfolders “thumbs” or “watermarks”?
                    if ($path !== '.' && $path !== '..' && $path !== 'thumbs' && $path !== 'watermark' && $recursive) {
                        foreach ($this->scanFolders($dir . $path . '/', $recursive) as $subpath) {
                            $files[] = $path . '/' . $subpath;
                        }
                    }
                } else {
                    $files[] = $path;
                }
            }
        }

        return $files;
    }
823473
public function findAll($directory): array
    {
        $cache = $this->cacheService->systemSimple();
        $key = \str_replace(['::', '\\'], '_', __METHOD__) . '_' . \crc32($directory);
        $result = $cache->get($key);
        if (!$result) {
            $result = $this->classHelper->getClassMap($directory, self::FILENAME);
            $cache->set($key, $result);
        }
        return $result;
    }
8377
protected function retrieveFiles(string $directory): array
    {
        $files = [];

        foreach (scandir($directory) as $file) {
            $elem = $this->pathHelper->join($directory, $file);

            if (
                $elem != '.' &&
                $elem != '..' &&
                \is_file($elem) &&
                \is_readable($elem) &&
                $this->stringHelper->endsWith($elem, '.yaml')
            ) {
                $files[] = $elem;
            }
        }

        if (count($files) == 0) {
            throw new FileSystemException('Path does not contain any readable yaml files!', 1527452904);
        }

        return $files;
    }
1277526
protected function _scanDir($dir)
    {
        $dir = new Folder($dir);
        $contents = $dir->read(true, true);
        if (empty($contents[1])) {
            return [];
        }
        $shells = [];
        foreach ($contents[1] as $file) {
            if (substr($file, -4) !== '.php') {
                continue;
            }
            $shells[] = substr($file, 0, -4);
        }

        return $shells;
    }
196904
public function listFiles($directory = null, $recursive = false)
    {
        return $this->flysystem->listFiles($directory, $recursive);
    }
306183
public static function getFilesRecursivelyWithSpecifiedExtension($dir, $extension)
    {
        $directory = new RecursiveDirectoryIterator($dir);
        $iterator = new RecursiveIteratorIterator($directory);
        $filter = new RegexIterator($iterator, "/\.$extension$/i", RecursiveRegexIterator::GET_MATCH);
        return array_keys(iterator_to_array($filter));
    }
314913
protected function searchRecursive( $pattern, $directory )
    {
        $itemArr = glob( $directory . $pattern );
        $dirArr = glob( $directory . "*", GLOB_ONLYDIR );
        foreach ( $dirArr as $dirEntry )
        {
            $result = $this->searchRecursive( $pattern, "$dirEntry/" );
            $itemArr = array_merge( $itemArr, $result );
        }
        return $itemArr;
    }
1257681
public function files($directory, $recursive = false)
    {
        $result     = [];
        $recursive  = boolval($recursive);

        if ( ! $this->isDirectory($directory)) return [];

        $items = new FilesystemIterator($directory);

        foreach ($items as $item) {
            if ($item->isFile()) {
                $result[]       = $item->getPathname();
            } elseif ($recursive && $item->isDir() && ! $item->isLink()) {
                $subFiles       = $this->files($item->getPathname(), $recursive);
                foreach ($subFiles as $file) {
                    $result[]   = $file;
                }
            }
        }

        return $result;
    }
598201
protected function scanClasses($dir, $depth = 2) {

        // Don't recurse if we've hit out depth limit
        if ($depth < 0) {
            return [];
        }

        $paths = scandir($dir);

        $classes = [];
        foreach ($paths as $path) {
            if (in_array($path, ['.','..'])) {
                continue;
            }

            $full = paths($dir,$path);

            if (is_dir($full)) {
                if ($depth > 0) {
                    $classes = array_merge($classes, $this->scanClasses($full, $depth-1));
                }
            } else {

                // Only scan PHP files
                if (fnmatch('*.php', $path)) {

                    $declarations = $this->scanFile($full);

                    // Iterate over all namespaces
                    foreach ($declarations as $namespaceRow) {
                        if (isset($namespaceRow['namespace']) && $namespaceRow) {
                            $namespace = rtrim($namespaceRow['namespace'], '\\').'\\';
                            $namespaceClasses = $namespaceRow['classes'];
                        } else {
                            $namespace = '';
                            $namespaceClasses = $namespaceRow;
                        }

                        // Iterate over all classes within NS
                        foreach ($namespaceClasses as $classRow) {
                            $className = $namespace.$classRow['name'];
                            $classes[strtolower($className)] = [$className, $full];

                            // Special case for main addon file
                            if ($classRow['type'] == 'CLASS') {
                                if (preg_match('`^[\w\d]+Addon$`', $classRow['name'])) {
                                    $this->special['addon'] = $className;
                                }
                            }
                        }
                    }
                }

            }
        }

        return $classes;
    }
1183349
public function index(array $directories, array $extensions = [])
    {
        $fileSystem = new Filesystem();
        $finder = new Finder();

        // reset the change set
        $this->changes = [];
        clearstatcache();

        foreach ($directories as $directory) {
            if (!$fileSystem->exists($directory)) {
                throw new Exception('The directory '.$directory.' does not exists');
            }

            // find all files in the given directory
            $finder
                ->files()
                ->in($directory)
            ;

            // eventually filtering by file extension
            foreach ($extensions as $extension) {
                $finder->name('*.'.$extension);
            }

            // index the results
            foreach ($finder as $file) {
                $this->add($file);
            }
        }

    }
1016649
private function scanDir($dir, $onlyDir = 0)
    {
        $files = array();
        foreach (glob($dir.'/*', $onlyDir) as $name) {
            if ($this->isShowFile($name, $this->driverOptions['showHidden'])) {
                $file = $this->getFileInfo($name);
                $this->setDirs($file, $name);
                $files[] = $file;
            }
        }

        return $files;
    }
1257721
public static function get_include_files( $directory, $exclude_underscore = false ) {
		$return = [
			'files'       => [],
			'directories' => [],
		];

		if ( ! is_dir( $directory ) ) {
			return $return;
		}

		$directory_iterator = new \DirectoryIterator( $directory );

		foreach ( $directory_iterator as $file ) {
			if ( $file->isDot() ) {
				continue;
			}

			if ( $file->isDir() ) {
				$return['directories'][] = $file->getPathname();
				continue;
			}

			if ( 'php' !== $file->getExtension() ) {
				continue;
			}

			if ( $exclude_underscore ) {
				if ( 0 === strpos( $file->getBasename(), '_' ) ) {
					continue;
				}
			}

			$return['files'][] = $file->getPathname();
		}

		return $return;
	}
10540
public function listContents(string $directory = '', bool $recursive = false): array
    {
        $list = [];
        $location = $this->applyBasePath($directory);

        if (! is_dir($location)) {
            return $list;
        }

        $iterator = $recursive ?
                    $this->getRecursiveDirectoryIterator($location) :
                    $this->getDirectoryIterator($location);

        foreach ($iterator as $file) {
            $path = $this->getFilePath($file);

            if (preg_match('#(^|/|\\\\)\.{1,2}$#', $path)) {
                continue;
            }

            $list[] = $this->normalizeFileInfo($file);

            unset($path);
        }

        unset($location, $iterator);

        return array_filter($list);
    }
373576
public function scanDir($directory = '.', $recursive = false)
    {
        return $this->parseRawList($this->rawlist($directory, $recursive));
    }