kiwilan / php-filelist
PHP package for recursive file listing, exportable in JSON format.
Fund package maintenance!
kiwilan
Requires
- php: ^8.1
Requires (Dev)
- laravel/pint: ^1.0
- pestphp/pest: ^2.20
- spatie/ray: ^1.28
This package is auto-updated.
Last update: 2024-11-21 14:45:28 UTC
README
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.
Installation
You can install the package via composer:
composer require kiwilan/php-filelist
Usage
$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`
Options
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();
Use custom binaries
If you want to add a new binary, you can open an issue or a pull request.
find
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();
scout-seeker
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();
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Credits
License
The MIT License (MIT). Please see License File for more information.