Finder class
Symfony\Component\Finder\Finder
Finder allows to build rules to find files and directories.
It is a thin wrapper around several specialized iterator classes.
All rules may be invoked several times.
All methods return the current Finder object to allow chaining:
$finder = Finder::create()->files()->name('*.php')->in(__DIR__);
Implements:
IteratorAggregate, Countable, Traversable
Defined in D:/WEBISTERS/projects/app/vendor/symfony/finder/Finder.php
Constants #
Properties #
- $mode
- -
- $names
- -
- $notNames
- -
- $exclude
- -
- $filters
- -
- $pruneFilters
- -
- $depths
- -
- $sizes
- -
- $followLinks
- -
- $reverseSorting
- -
- $sort
- -
- $ignore
- -
- $dirs
- -
- $dates
- -
- $iterators
- -
- $contains
- -
- $notContains
- -
- $paths
- -
- $notPaths
- -
- $ignoreUnreadableDirs
- -
- $vcsPatterns
- -
$mode
$names
$notNames
$exclude
$filters
$pruneFilters
$depths
$sizes
$followLinks
$reverseSorting
$sort
$ignore
$dirs
$dates
$iterators
$contains
$notContains
$paths
$notPaths
$ignoreUnreadableDirs
$vcsPatterns
Methods #
- __construct()
- -
- addVCSPattern()
- Adds VCS patterns.
- append()
- Appends an existing set of files/directories to the finder.
- contains()
- Adds tests that file contents must match.
- count()
- Counts all the results collected by the iterators.
- create()
- Creates a new Finder.
- date()
- Adds tests for file dates (last modified).
- depth()
- Adds tests for the directory depth.
- directories()
- Restricts the matching to directories only.
- exclude()
- Excludes directories.
- files()
- Restricts the matching to files only.
- filter()
- Filters the iterator with an anonymous function.
- followLinks()
- Forces the following of symlinks.
- getIterator()
- Returns an Iterator for the current Finder configuration.
- hasResults()
- Check if any results were found.
- ignoreDotFiles()
- Excludes "hidden" directories and files (starting with a dot).
- ignoreUnreadableDirs()
- Tells finder to ignore unreadable directories.
- ignoreVCS()
- Forces the finder to ignore version control directories.
- ignoreVCSIgnored()
- Forces Finder to obey .gitignore and ignore files based on rules listed there.
- in()
- Searches files and directories which match defined rules.
- name()
- Adds rules that files must match.
- notContains()
- Adds tests that file contents must not match.
- notName()
- Adds rules that files must not match.
- notPath()
- Adds rules that filenames must not match.
- path()
- Adds rules that filenames must match.
- reverseSorting()
- Reverses the sorting.
- size()
- Adds tests for file sizes.
- sort()
- Sorts files and directories by an anonymous function.
- sortByAccessedTime()
- Sorts files and directories by the last accessed time.
- sortByCaseInsensitiveName()
- Sorts files and directories by name case insensitive.
- sortByChangedTime()
- Sorts files and directories by the last inode changed time.
- sortByExtension()
- Sorts files and directories by extension.
- sortByModifiedTime()
- Sorts files and directories by the last modified time.
- sortByName()
- Sorts files and directories by name.
- sortBySize()
- Sorts files and directories by size.
- sortByType()
- Sorts files and directories by type (directories before files), then by name.
- normalizeDir()
- Normalizes given directory names by removing trailing slashes.
- searchInDirectory()
- -
__construct()
addVCSPattern()
Adds VCS patterns.
- array|string $pattern - VCS patterns to ignore
append()
Appends an existing set of files/directories to the finder.
The set can be another Finder, an Iterator, an IteratorAggregate, or even a plain array.
- iterable $iterator
contains()
Adds tests that file contents must match.
Strings or PCRE patterns can be used:
$finder->contains('Lorem ipsum')
$finder->contains('/Lorem ipsum/i')
$finder->contains(['dolor', '/ipsum/i'])
- array|string $patterns - A pattern (string or regexp) or an array of patterns
count()
Counts all the results collected by the iterators.
create()
Creates a new Finder.
date()
Adds tests for file dates (last modified).
The date must be something that strtotime() is able to parse:
$finder->date('since yesterday');
$finder->date('until 2 days ago');
$finder->date('> now - 2 hours');
$finder->date('>= 2005-10-15');
$finder->date(['>= 2005-10-15', '<= 2006-05-27']);
- array|string $dates - A date range string or an array of date ranges
depth()
Adds tests for the directory depth.
Usage:
$finder->depth('> 1') // the Finder will start matching at level 1.
$finder->depth('< 3') // the Finder will descend at most 3 levels of directories below the starting point.
$finder->depth(['>= 1', '< 3'])
- array|string|int $levels - The depth level expression or an array of depth levels
directories()
Restricts the matching to directories only.
exclude()
Excludes directories.
Directories passed as argument must be relative to the ones defined with the `in()` method. For example:
$finder->in(__DIR__)->exclude('ruby');
- array|string $dirs - A directory path or an array of directories
files()
Restricts the matching to files only.
filter()
Filters the iterator with an anonymous function.
The anonymous function receives a \SplFileInfo and must return false
to remove files.
- Closure $closure
- bool $prune - Whether to skip traversing directories further
followLinks()
Forces the following of symlinks.
getIterator()
Returns an Iterator for the current Finder configuration.
This method implements the IteratorAggregate interface.
hasResults()
Check if any results were found.
ignoreDotFiles()
Excludes "hidden" directories and files (starting with a dot).
This option is enabled by default.
- bool $ignoreDotFiles
ignoreUnreadableDirs()
Tells finder to ignore unreadable directories.
By default, scanning unreadable directories content throws an AccessDeniedException.
- bool $ignore
ignoreVCS()
Forces the finder to ignore version control directories.
This option is enabled by default.
- bool $ignoreVCS
ignoreVCSIgnored()
Forces Finder to obey .gitignore and ignore files based on rules listed there.
This option is disabled by default.
- bool $ignoreVCSIgnored
in()
Searches files and directories which match defined rules.
- array|string $dirs - A directory path or an array of directories
name()
Adds rules that files must match.
You can use patterns (delimited with / sign), globs or simple strings.
$finder->name('/\.php$/')
$finder->name('*.php') // same as above, without dot files
$finder->name('test.php')
$finder->name(['test.py', 'test.php'])
- array|string $patterns - A pattern (a regexp, a glob, or a string) or an array of patterns
notContains()
Adds tests that file contents must not match.
Strings or PCRE patterns can be used:
$finder->notContains('Lorem ipsum')
$finder->notContains('/Lorem ipsum/i')
$finder->notContains(['lorem', '/dolor/i'])
- array|string $patterns - A pattern (string or regexp) or an array of patterns
notName()
Adds rules that files must not match.
- array|string $patterns - A pattern (a regexp, a glob, or a string) or an array of patterns
notPath()
Adds rules that filenames must not match.
You can use patterns (delimited with / sign) or simple strings.
$finder->notPath('some/special/dir')
$finder->notPath('/some\/special\/dir/') // same as above
$finder->notPath(['some/file.txt', 'another/file.log'])
Use only / as dirname separator.
- array|string $patterns - A pattern (a regexp or a string) or an array of patterns
path()
Adds rules that filenames must match.
You can use patterns (delimited with / sign) or simple strings.
$finder->path('some/special/dir')
$finder->path('/some\/special\/dir/') // same as above
$finder->path(['some dir', 'another/dir'])
Use only / as dirname separator.
- array|string $patterns - A pattern (a regexp or a string) or an array of patterns
reverseSorting()
Reverses the sorting.
size()
Adds tests for file sizes.
$finder->size('> 10K');
$finder->size('<= 1Ki');
$finder->size(4);
$finder->size(['> 10K', '< 20K'])
- array|string|int $sizes - A size range string or an integer or an array of size ranges
sort()
Sorts files and directories by an anonymous function.
The anonymous function receives two \SplFileInfo instances to compare.
This can be slow as all the matching files and directories must be retrieved for comparison.
- Closure $closure
sortByAccessedTime()
Sorts files and directories by the last accessed time.
This is the time that the file was last accessed, read or written to.
This can be slow as all the matching files and directories must be retrieved for comparison.
sortByCaseInsensitiveName()
Sorts files and directories by name case insensitive.
This can be slow as all the matching files and directories must be retrieved for comparison.
- bool $useNaturalSort
sortByChangedTime()
Sorts files and directories by the last inode changed time.
This is the time that the inode information was last modified (permissions, owner, group or other metadata).
On Windows, since inode is not available, changed time is actually the file creation time.
This can be slow as all the matching files and directories must be retrieved for comparison.
sortByExtension()
Sorts files and directories by extension.
This can be slow as all the matching files and directories must be retrieved for comparison.
sortByModifiedTime()
Sorts files and directories by the last modified time.
This is the last time the actual contents of the file were last modified.
This can be slow as all the matching files and directories must be retrieved for comparison.
sortByName()
Sorts files and directories by name.
This can be slow as all the matching files and directories must be retrieved for comparison.
- bool $useNaturalSort
sortBySize()
Sorts files and directories by size.
This can be slow as all the matching files and directories must be retrieved for comparison.
sortByType()
Sorts files and directories by type (directories before files), then by name.
This can be slow as all the matching files and directories must be retrieved for comparison.
normalizeDir()
Normalizes given directory names by removing trailing slashes.
Excluding: (s)ftp:// or ssh2.(s)ftp:// wrapper
- string $dir
searchInDirectory()
- string $dir