public static function listFilesRecursively(string $directory, bool $absolutePath = true, string ...$extensions): array
    {
        $paths = array();
        if (!is_dir($directory)) {
            return $paths;
        }
        
        $directoryIterator = new \RecursiveDirectoryIterator($directory);
        $recursiveIterator = new \RecursiveIteratorIterator($directoryIterator, \RecursiveIteratorIterator::SELF_FIRST);
        
        foreach ($recursiveIterator as $file) {
            if (!empty($extensions) && !in_array('.' . $file->getExtension(), $extensions)) {
                continue;
            }
            
            $path = $file->getPathName();
            if (!$absolutePath) {
                $path = substr($path, strlen($directory));
            }
            
            $paths[] = $path;
        }
        
        return $paths;
    }
public static function listFilesRecursively(string $directory, bool $absolutePath = true, string ...$extensions): array
    {
        $paths = array();
        if (!is_dir($directory)) {
            return $paths;
        }
        
        $directoryIterator = new \RecursiveDirectoryIterator($directory);
        $recursiveIterator = new \RecursiveIteratorIterator($directoryIterator, \RecursiveIteratorIterator::SELF_FIRST);
        
        foreach ($recursiveIterator as $file) {
            if (!empty($extensions) && !in_array('.' . $file->getExtension(), $extensions)) {
                continue;
            }
            
            $path = $file->getPathName();
            if (!$absolutePath) {
                $path = substr($path, strlen($directory));
            }
            
            $paths[] = $path;
        }
        
        return $paths;
    }
public static function listFilesRecursively ( string $ directory , bool $ absolutePath = true , string ... $ extensions ) : array { $ paths = array ( ) ; if ( ! is_dir ( $ directory ) ) { return $ paths ; } $ directoryIterator = new \ RecursiveDirectoryIterator ( $ directory ) ; $ recursiveIterator = new \ RecursiveIteratorIterator ( $ directoryIterator , \ RecursiveIteratorIterator :: SELF_FIRST ) ; foreach ( $ recursiveIterator as $ file ) { if ( ! empty ( $ extensions ) && ! in_array ( '.' . $ file -> getExtension ( ) , $ extensions ) ) { continue ; } $ path = $ file -> getPathName ( ) ; if ( ! $ absolutePath ) { $ path = substr ( $ path , strlen ( $ directory ) ) ; } $ paths [ ] = $ path ; } return $ paths ; }
List all files in the specified directory and its subdirectories.

@param string $directory
Path to the directory to list the files for.

@param boolean $absolutePath
Whether to return an absolute path for each file or relative.

@param string[] $extensions
File extension. Files to be listed have this extension this if specified.

@return string[] Files in the specified directory and its subdirectores, having the optional extensions if specified.
List all files in the specified directory and its subdirectories .