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 easy chaining:
$finder = Finder::create()->files()->name('*.php')->in(__DIR__);
use Symfony\Component\Finder\Finder; $finder = new Finder(); // find all .txt files in current directory and sub-directories $iterator = $finder->files()->name('*.txt')->in(__DIR__); foreach ($iterator as $file) { echo $file->getFilename()."\n"; }
use Symfony\Component\Finder\Finder; $finder = new Finder(); // find all directories containing .php files and more than 2 levels deep $iterator = $finder->directories() ->name('*') ->depth('> 2') ->contains('*.php') ->in(__DIR__); foreach ($iterator as $directory) { echo $directory->getRelativePathname()."\n"; }This example demonstrates how to find all directories containing `.php` files and more than two levels deep using the `Finder` component. In both examples, we create an instance of the `Finder` class, apply some conditions to it, and then iterate over the search results using a `foreach` loop. The Finder component is part of the Symfony Finder component library.