IGNORE_VCS_FILES
IGNORE_VCS_FILES = 1
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__);
depth(string|int|string[]|int[] $levels) : $this
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'])
string|int|string[]|int[] | $levels | The depth level expression or an array of depth levels |
date(string|string[] $dates) : $this
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']);
string|string[] | $dates | A date range string or an array of date ranges |
name(string|string[] $patterns) : $this
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 $finder->name('test.php') $finder->name(['test.py', 'test.php'])
string|string[] | $patterns | A pattern (a regexp, a glob, or a string) or an array of patterns |
contains(string|string[] $patterns) : $this
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'])
string|string[] | $patterns | A pattern (string or regexp) or an array of patterns |
notContains(string|string[] $patterns) : $this
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'])
string|string[] | $patterns | A pattern (string or regexp) or an array of patterns |
path(string|string[] $patterns) : $this
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.
string|string[] | $patterns | A pattern (a regexp or a string) or an array of patterns |
notPath(string|string[] $patterns) : $this
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.
string|string[] | $patterns | A pattern (a regexp or a string) or an array of patterns |
size(string|int|string[]|int[] $sizes) : $this
Adds tests for file sizes.
$finder->size('> 10K'); $finder->size('<= 1Ki'); $finder->size(4); $finder->size(['> 10K', '< 20K'])
string|int|string[]|int[] | $sizes | A size range string or an integer or an array of size ranges |
sort(\Closure $closure) : $this
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 |
sortByChangedTime() : $this
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.
in(string|string[] $dirs) : $this
Searches files and directories which match defined rules.
string|string[] | $dirs | A directory path or an array of directories |
if one of the directories does not exist
append(iterable $iterator) : $this
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 |
when the given argument is not iterable