Returns an array of scanned files or counts them
@param string $directory
@param array $options
@return array|integer
551097
public function scan($directory, array $options = array())
    {
        set_time_limit(0);

        $options += array(
            'sort' => null,
            'order' => null,
            'filter_key' => null,
            'filter_value' => null
        );

        $result = null;
        $this->hook->attach('module.file_manager.scan.before', $directory, $options, $result, $this);

        if (isset($result)) {
            return $result;
        }

        $filters = $this->getFilters();
        $iterator = new Filter(new FilesystemIterator($directory), $options, $filters);

        if (!empty($options['count'])) {
            return iterator_count($iterator);
        }

        if (!empty($options['limit'])) {
            list($page, $limit) = $options['limit'];
            $iterator = new LimitIterator($iterator, $page, $limit);
        }

        $result = iterator_to_array($iterator);
        $this->sort($result, $options['sort'], $options['order']);

        $this->hook->attach('module.file_manager.scan.after', $directory, $options, $result, $this);
        return $result;
    }
426430
private function get_templates($directory) {
		$templates = [];
		foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($directory), \RecursiveIteratorIterator::LEAVES_ONLY) as $file)
		{
		    if ($file->isFile() === false) {
		        continue;
		    }

			if ($file->getExtension() != 'twig' && $file->getExtension() != 'tpl') {
				continue;
			}

		    $resource = str_replace($directory, '', $file);
		    $templates[] = $resource;
		}

		return $templates;
	}
1347837
public static function listContents(string $directory = '', bool $recursive = false)
    {
        $result = [];

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

        $iterator = $recursive ? Filesystem::getRecursiveDirectoryIterator($directory) : Filesystem::getDirectoryIterator($directory);

        foreach ($iterator as $file) {
            $path = Filesystem::getFilePath($file);

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

            $result[] = Filesystem::normalizeFileInfo($file);
        }

        return array_filter($result);
    }
260977
public function getFilesFromFal(&$files, $directoryArray)
    {
        foreach ($directoryArray as $directory) {
            $folder = $this->storage->getFolder($directory);

            if ($folder->getName() != '_temp_') {
                $filesInFolder = $folder->getFiles();
                if (count($filesInFolder)) {
                    foreach ($filesInFolder as $file) {
                        if (GeneralUtility::inList($this->pObj->indexerConfig['fileext'], $file->getExtension())) {
                            $files[] = $file;
                        }
                    }
                }

                // do recursion
                $subfolders = $folder->getSubFolders();
                if (count($subfolders)) {
                    foreach ($subfolders as $subfolder) {
                        $this->getFilesFromFal($files, array($subfolder->getIdentifier()));
                    }
                }
            }
        }
    }
57668
public function readFile($filePath = null, array $options = [])
    {
        $filePath = empty($filePath)
            ? $this->filePath
            : $filePath;


        $result = [];

        if (extension_loaded('zip')) {
            if ($zipHandle = zip_open($filePath)) {
                while ($zipContent = zip_read($zipHandle)) {
                    $result[] = zip_entry_name($zipContent);
                }

                zip_close($zipHandle);
            }
        }

        return $result;
    }
1144709
public function listDirectory($directory)
    {
        $result = @ftp_nlist($this->connection, $directory);
        
        if ($result === false) {
            throw new Exception('Unable to list directory');
        }
        
        asort($result);

        return $result;
    }
198684
public function ls($directory = null)
        {
            $list = array();

            // attempt to get list
            if($list = ftp_nlist(static::$_stream, $directory)) {
                // success
                return $list;
            // fail
            } else {
                static::$error = "Failed to get directory list";
                return array();
            }
        }
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;
    }
240893
public static function delete(string $dir, array $options = []) : bool {
		if (is_dir($dir) && !is_link($dir)) {
			$skip_files = [];
			if (!empty($options['skip_files'])) {
				$skip_files = $options['skip_files'];
				$options['only_contents'] = true;
			}
			$skip_files[] = '.';
			$skip_files[] = '..';
			$objects = scandir($dir);
			foreach ($objects as $v) {
				if (!in_array($v, $skip_files)) {
					if (!self::delete($dir . DIRECTORY_SEPARATOR . $v, $options)) return false;
				}
			}
			if (empty($options['only_contents'])) {
				return rmdir($dir);
			} else {
				return true;
			}
		} else if (file_exists($dir)) {
			return unlink($dir);
		} else {
			return false;
		}
	}
596912
public function items($directory)
    {
        $directory = ltrim($directory, "/");

        $iterator = new FilesystemIterator($this->pathRoot.$directory);

        $files = array();

        foreach ($iterator as $file) {
            $files[] = strval($file);
        }
        
        return $files;
    }
282616
static public function getFiles( $dir, $recursive = false )
    {
        $files = [];
        if ( ( $dh = opendir( $dir ) ) ) {
            while ( ( $file = readdir( $dh ) ) !== false ) {
                if ( is_file( $dir . '/' . $file ) ) {
                    $files[] = $file;
                }
                if ( $recursive && ( $file !== '.' && $file !== '..' && is_dir( $dir . '/' . $file ) ) ) {
                    $files = array_merge( $files, self::getFiles( $dir . DS . $file, true ) );
                }
            }
            closedir( $dh );
        }
        return $files;
    }
710728
public static function iterate(string $dir, array $options = []) : array {
		$result = [];
		$relative_path = realpath($dir);
		if (empty($options['recursive'])) {
			$iterator = new \DirectoryIterator($dir);
		} else {
			$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir));
		}
		foreach ($iterator as $v) {
			if (method_exists($v, 'isDot')) {
				if ($v->isDot()) {
					continue;
				}
			} else {
				$filename = $v->getFilename();
				if ($filename === '.' || $filename === '..') {
					continue;
				}
			}
			if (!empty($options['only_extensions']) && !in_array($v->getExtension(), $options['only_extensions'])) {
				continue;
			}
			if (!empty($options['only_files']) && !in_array($filename, $options['only_files'])) {
				continue;
			}
			if (empty($options['extended'])) {
				$result[] = $v->getPathname();
			} else {
				$pathname = $v->getPathname();
				$result[$pathname] = [
					'pathname' => $pathname,
					'access' => $v->getATime(),
					'modified' => $v->getMTime(),
					'permissions' => $v->getPerms(),
					'size' => $v->getSize(),
					'type' => $v->getType(),
					'directory' => $v->getPath(),
					'basename' => $v->getBasename(),
					'filename' => $v->getFilename(),
					'relative_directory' => self::iterateProcessPathInnerHelper($v->getPath(), $relative_path),
				];
			}
		}
		return $result;
	}
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;
    }
924785
public function getFiles(...$options)
    {
        if ($this->files === null) {
            $ds = $this->getDirectoryScanner($this->getProject());
            $this->files = $ds->getIncludedFiles();
        } // if ($this->files===null)

        return $this->files;
    }
373576
public function scanDir($directory = '.', $recursive = false)
    {
        return $this->parseRawList($this->rawlist($directory, $recursive));
    }
948237
public function scanDir($dir)
    {
        return collect(scandir($dir))->map(function ($item) use ($dir) {
            return $dir.DIRECTORY_SEPARATOR.$item;
        });
    }
56662
public function files($directory, $pattern = '*', $extensions = '')
    {
        $all = array_filter($this->listDirectory($directory), function ($path) {
            return $this->type($path) == 'file';
        });

        $extensions = $extensions ? (array)$extensions : [];

        return $this->filterPaths($all, $pattern, $extensions);

    }