PHP package for recursive file listing, exportable in JSON format.
Note
The aim of this package is to provide a simple way to list files in a directory, with options to customize the scan. But the real feature is usage of custom binaries, if you want to add an interesting binary, you can open an issue or a pull request.
You can install the package via composer:
composer require kiwilan/php-filelist
$list = FileList::make('/path/to/scan')->run();
$list->getFiles(); // List of files as `string[]`
$list->getSplFiles(); // List of SplFileInfo as `SplFileInfo[]`
$list->getErrors(); // List of errors as `string[]|null`
$list->getTimeElapsed(); // Time elapsed in seconds as `float`
$list->getTotal(); // Total files as `int`
$list->isSuccess(); // Success status as `bool`
Show hidden files, default is false
.
$list = FileList::make('/path/to/scan')->showHidden()->run();
Save as JSON.
$list = FileList::make('/path/to/scan')->saveAsJson('/path/to/json')->run();
Throw exception on error, otherwise errors are stored in the list.
$list = FileList::make('/path/to/scan')->throwOnError()->run();
Limit the number of files to scan.
$list = FileList::make('/path/to/scan')->limit(100)->run();
Get only files with specific extensions, case insensitive.
$list = FileList::make('/path/to/scan')->onlyExtensions(['txt', 'md'])->run();
Skip extensions, case insensitive.
$list = FileList::make('/path/to/scan')->skipExtensions(['txt', 'md'])->run();
Skip filenames.
$list = FileList::make('/path/to/scan')->skipFilenames(['file.txt', 'README.md'])->run();
Disable recursive scan.
$list = FileList::make('/path/to/scan')->notRecursive()->run();
Disable PHP memory limit.
$list = FileList::make('/path/to/scan')->noMemoryLimit()->run();
If you want to add a new binary, you can open an issue or a pull request.
The find
binary is used to list files in a directory, you can add path of binary as parameter of withFind()
method if it's not in your PATH.
$list = FileList::make('/path/to/scan')->withFind()->run();
The scout-seeker
binary is used to list files in a directory, you can add path of binary as parameter of withScoutSeeker()
method if it's not in your PATH.
Important
You can install scout-seeker
(v0.2.11 min) with Cargo (Rust package manager):
cargo install scout-seeker
Binary scout-seeker
is a Rust CLI tool built to list files, you can find the source code here.
$list = FileList::make('/path/to/scan')->withScoutSeeker()->run();
composer test
Please see CHANGELOG for more information on what has changed recently.
The MIT License (MIT). Please see License File for more information.