List of directory’s file recursively with subfolders.

@param	string	Relative path of the interested folder to scan.
@param	string	Internal, subfolder recursive name-cache.
@param	array	Internal, empty array at first scan.

@return	array
504421
public static function getDirectoryFilenames($path, $subfolder=NULL, $fileList=array()) {
	
		// list of files to exclude
		$excludes = array('..', '.', '.DS_Store', 'thumbs.db', '.htaccess');
		
		try {
			
			// reads folders file and dirs as plain array
			$filenames = array_diff(scandir($path, 0), $excludes);
			
			// we look at each file/dir
			foreach ($filenames as $filename) {
	
				// relative file-path
				$file = $path . '/' . $filename;
		
				// it’s a directory, scan it
				if (is_dir($file)) {
	
					// recursive callback to scan new directory
					$fileList = self::getDirectoryFilenames($file, $subfolder . $filename . '/', $fileList);
						
				// it’s file, add it
				} else {
	
					$fileList[] = $subfolder . $filename;
						
				}
					
			}
	
		} catch (\Exception $e) {

			trigger_error($e->getMessage());
			return array();
			
		}
	
		return $fileList;
	
	}
1187341
protected function _scandir($path) {
		$files = array();

 		foreach (ftp_rawlist($this->connect, $path) as $str) {
 			if (($stat = $this->parseRaw($str))) {
 				$files[] = $path.DIRECTORY_SEPARATOR.$stat['name'];
 			}
 		}

 		return $files;
	}
1198103
private static function getDirFiles($absolute_dir, $relative_dir, &$files) {
        $handler = opendir($absolute_dir);
        if ( $handler != false ) {
            while ( $filename = readdir($handler) ) {
                if ( $filename != "." && $filename != ".." ) {
                    if ( is_dir($absolute_dir."/".$filename) ) {
                        self::getDirFiles($absolute_dir."/".$filename, $relative_dir.$filename."/", $files);
                    } else {
                        $files[] = $relative_dir.$filename;
                    }
                }
            }
            closedir($handler);
        }
    }
690222
private function getCacheFiles()
    {
        if (!($files = @scandir($this->directory, 1))) {
            return false;
        }

        $negExtLen = -1 * strlen($this->extension);
        $return = array();
        foreach ($files as $file) {
            if (substr($file, $negExtLen) === $this->extension) {
                $return[] = $this->directory . '/' . $file;
            }
        }
        return $return;
    }
713751
public static function recursive($path)
    {
        if (is_dir($path)) {
            $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::CHILD_FIRST);
            foreach ($iterator as $file) {
                self::_deleteFile($file);
            }
            rmdir($path);
        }
    }
641086
public function getCacheInfo() {

		if(($cachePath = $this->folder->getCachePath(TRUE))) {
			$size	= 0;
			$count	= 0;

			$di	= new \DirectoryIterator($cachePath);

			foreach($di as $fileinfo) {
				if(	$fileinfo->isDot() ||
					!$fileinfo->isFile() ||
					strpos($fileinfo->getFilename(), $this->filename) !== 0
				) {
					continue;
				}
				++$count;
				$size += $fileinfo->getSize();
			}
			return ['count' => $count, 'totalSize' => $size];
		}
		return FALSE;
	}
503402
public function listContents($directory = '', $recursive = false)
    {
        $files = [];
        foreach($this->listDirContents($directory) as $k => $file) {
            $pathInfo = pathinfo($file['key']);
            $files[] = array_merge($pathInfo, $this->normalizeData($file), [
                'type' => isset($pathInfo['extension']) ? 'file' : 'dir',
            ]);
        }
        return $files;
    }
1350599
private function recurseThroughDirectory($baseDir, $lookingFor = "/(.*)\.php$/i")
    {
        $results = array();
        $di = new RecursiveDirectoryIterator($baseDir);

        $this->output->writeLn("Scanning $baseDir...");

        foreach (new RecursiveIteratorIterator($di) as $filename => $file) {
            if (preg_match($lookingFor, $filename)) {
                $results[] = $this->extractFrom($filename);
            }
        }

        return $results;
    }
1286503
protected function scanSingle($path)
    {
        $files      = [];
        $detections = [];
        $path       = realpath($path);

        if (!$path) {
            throw new \InvalidArgumentException(sprintf('File to scan does not exist: %s', $path));
        }

        if (is_dir($path)) {
            $paths = [$path];

            return $this->scanDir($path);
        } else {
            $files[] = $path;
            if ($detection = $this->detect($path)) {
                $detections[] = $detection;
            }

            return new ScanResult([$path], $files, $detections);
        }
    }
1164527
public static function listFiles($path, array $ext = null, $returnRelative = false, &$files = [])
    {
        $path = Normalize::diskFullPath($path);

        if (!Directory::exist($path)) {
            return [];
        }

        $dir = opendir($path . '/.');
        while ($item = readdir($dir)) {
            if (is_file($sub = $path . '/' . $item)) {
                $item_ext = Str::lastIn($item, '.');
                if ($ext === null || Arr::in($item_ext, $ext)) {
                    if ($returnRelative) {
                        $files[] = $item;
                    } else {
                        $files[] = $path . DIRECTORY_SEPARATOR . $item;
                    }
                }
            } else {
                if ($item !== '.' && $item !== '..') {
                    self::listFiles($sub, $ext, $returnRelative, $files);
                }
            }
        }

        return $files;
    }
626872
public function loadExistingStatementsFromCache($file_path)
    {
        $root_cache_directory = Config::getInstance()->getCacheDirectory();

        if (!$root_cache_directory) {
            return;
        }

        $file_cache_key = $this->getParserCacheKey(
            $file_path
        );

        $parser_cache_directory = $root_cache_directory . DIRECTORY_SEPARATOR . self::PARSER_CACHE_DIRECTORY;

        $cache_location = $parser_cache_directory . DIRECTORY_SEPARATOR . $file_cache_key;

        if (is_readable($cache_location)) {
            if ($this->use_igbinary) {
                /** @var array<int, \PhpParser\Node\Stmt> */
                return igbinary_unserialize((string)file_get_contents($cache_location)) ?: null;
            }

            /** @var array<int, \PhpParser\Node\Stmt> */
            return unserialize((string)file_get_contents($cache_location)) ?: null;
        }
    }
710179
protected function _scandir($path) {
		$files = array();
		
		foreach (scandir($path) as $name) {
			if ($name != '.' && $name != '..') {
				$files[] = $path.DIRECTORY_SEPARATOR.$name;
			}
		}
		return $files;
	}
1217774
def find_files_relative(directory, files)
      return [] unless files.any?
      files.each_with_object([]) do |file, obj|
        path = "#{directory}/#{file}"
        obj << path if File.exist?(path)
      end
    end
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;
    }
1270581
static function recursiveFileSearch(string $path, $searchmask = '*') {
        $path = \rtrim($path, '/');
        
        $files = array();
        if(is_array($searchmask)) {
            $csearchmask = \count($searchmask);
            
            for($i = 0; $i < $csearchmask; $i++) {
                $files = \array_merge($files, \glob($path.'/'.$searchmask[$i]));
            }
            
            \sort($files);
        } else {
            $files = \glob($path.'/'.$searchmask);
        }
        
        
        $dirs = \glob($path.'/*', GLOB_ONLYDIR);
        foreach($dirs as $dir) {
            if(\is_dir($dir)) {
                $files = \array_merge($files, self::recursiveFileSearch($dir, $searchmask));
            }
        }
        
        \sort($files);
        return $files;
    }
553140
protected function _list($path, $prefix = '', $mode = 'file', $recursive = false, $filter = null)
    {
        $files  = [];
        $ignore = ['.', '..', '.DS_Store', '.svn', '.git', '.gitignore', '.gitmodules', 'cgi-bin'];

        if ($scan = @scandir($path)) {
            foreach ($scan as $file) {
                // continue if ignore match
                if (Arr::in($file, $ignore)) {
                    continue;
                }

                if (is_dir($path . '/' . $file)) {
                    // add dir
                    if ($mode === 'dir') {
                        // continue if no regex filter match
                        if ($filter && !preg_match($filter, $file)) {
                            continue;
                        }

                        $files[] = $prefix . $file;
                    }

                    // continue if not recursive
                    if (!$recursive) {
                        continue;
                    }

                    // read subdirectory
                    $files = array_merge(
                        $files,
                        $this->_list($path . '/' . $file, $prefix . $file . '/', $mode, $recursive, $filter)
                    );

                } else {
                    // add file
                    if ($mode === 'file') {
                        // continue if no regex filter match
                        if ($filter && !preg_match($filter, $file)) {
                            continue;
                        }

                        $files[] = $prefix.$file;
                    }
                }
            }
        }

        return $files;
    }
128282
private static function retrieveFilesFromPaths(array $paths): iterable
    {
        if ([] === $paths) {
            return [];
        }

        $pathsToSearch = [];
        $filesToAppend = [];

        foreach ($paths as $path) {
            if (false === file_exists($path)) {
                throw new RuntimeException(
                    sprintf(
                        'Could not find the file "%s".',
                        $path
                    )
                );
            }

            if (is_dir($path)) {
                $pathsToSearch[] = $path;
            } else {
                $filesToAppend[] = $path;
            }
        }

        $finder = new Finder();

        $finder->files()
            ->in($pathsToSearch)
            ->append($filesToAppend)
            ->filter(static function (SplFileInfo $fileInfo): ?bool {
                if ($fileInfo->isLink()) {
                    return false;
                }

                return null;
            })
            ->sortByName()
        ;

        return $finder;
    }