-
Notifications
You must be signed in to change notification settings - Fork 1
FileFinder
For a more flexible way to search for files than the FileFinder::findFiles()
method, you can use the file finder class.
Simply create an instance of it with the existing factory method:
use AppUtils;
$finder = FileHelper::createFileFinder('/path/to/folder');
Setting up the finder is easy to do, provided your development IDE provides function insight.
use AppUtils;
$files = FileHelper::createFileFinder('/path/to/folder')
->includeExtension('txt')
->getAll();
This will fetch all .txt
files in the target folder and all subfolders, with absolute paths.
use AppUtils;
$files = FileHelper::createFileFinder('/path/to/folder')
->includeExtension('txt')
->makeRecursive()
->getAll();
This will fetch all files from the folder and its subfolders, returning paths relative to the target folder.
use AppUtils;
$files = FileHelper::createFileFinder('/path/to/folder')
->makeRecursive()
->setPathmodeRelative()
->getAll();
This will fetch only the file names of all files in the folder.
use AppUtils;
$files = FileHelper::createFileFinder('/path/to/folder')
->stripExtensions() // remove extensions
->setPathmodeStrip() // remove the path
->getAll();
This will fetch all files from the folder, excluding PDF files.
use AppUtils;
$files = FileHelper::createFileFinder('/path/to/folder')
->excludeExtension('pdf')
->getAll();
New here?
Have a look at the overview for a list of all helper classes available in the package.
Table of contents
Find the current page in the collapsible "Pages" list above, and expand the page, to view a table of contents.