findFiles.php
Table of Contents
Functions
- findFiles() : array<string|int, SplFileInfo>
- Lists files in a directory with advanced filtering, sorting, and recursive options.
Functions
findFiles()
Lists files in a directory with advanced filtering, sorting, and recursive options.
findFiles(string|null $directory[, array{filter?: callable|null, followLinks?: bool|null, includeDots?: bool|null, mode?: string|null, order?: string|null, pattern?: string|array|null, recursive?: bool|null, sort?: callable|string|array|null} $options = [] ]) : array<string|int, SplFileInfo>
This function provides flexible options for retrieving files and directories from a given path. It supports recursive search, glob and regex pattern matching, sorting, symbolic link following, and custom filters.
Parameters
- $directory : string|null
-
The target directory path. If null or invalid, a DirectoryException is thrown.
- $options : array{filter?: callable|null, followLinks?: bool|null, includeDots?: bool|null, mode?: string|null, order?: string|null, pattern?: string|array|null, recursive?: bool|null, sort?: callable|string|array|null} = []
-
Optional settings to customize the file listing.
- filter : A function to map or transform each SplFileInfo result.
- followLinks : Whether to follow symbolic links (default: false).
- includeDots : Whether to include dot files (default: false).
- mode : Filter by type: 'files', 'dirs', or 'both' (default: 'files').
- order : Sort order: 'asc' (default) or 'desc'.
- pattern : A glob pattern, regex, or list of patterns to match file names.
- recursive : Whether to search recursively (default: false).
- sort : A sort option, eg: callback, predefined string, or array of keys.