Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/php-toolkit/fsutil
Useful filesystem util for PHP. file and dir operation, files find, file tree build.
https://github.com/php-toolkit/fsutil
file-finder file-tree filesystem
Last synced: 22 days ago
JSON representation
Useful filesystem util for PHP. file and dir operation, files find, file tree build.
- Host: GitHub
- URL: https://github.com/php-toolkit/fsutil
- Owner: php-toolkit
- License: mit
- Created: 2020-06-10T08:51:08.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-12-05T10:46:17.000Z (about 2 months ago)
- Last Synced: 2024-12-05T11:37:53.588Z (about 2 months ago)
- Topics: file-finder, file-tree, filesystem
- Language: PHP
- Homepage:
- Size: 151 KB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# FileSystem Util
[![License](https://img.shields.io/packagist/l/toolkit/fsutil.svg?style=flat-square)](LICENSE)
[![Php Version](https://img.shields.io/badge/php-%3E=8.0-brightgreen.svg?maxAge=2592000)](https://packagist.org/packages/toolkit/fsutil)
[![Latest Stable Version](http://img.shields.io/packagist/v/toolkit/fsutil.svg)](https://packagist.org/packages/toolkit/fsutil)
[![Actions Status](https://github.com/php-toolkit/fsutil/workflows/Unit-tests/badge.svg)](https://github.com/php-toolkit/fsutil/actions)Some useful file system util for php
- basic filesystem operation
- file read/write operation
- directory operation
- file modify watcher
- files finder
- file tree builder## Install
- Required PHP 8.0+
```bash
composer require toolkit/fsutil
```## File Finder
```php
use Toolkit\FsUtil\Extra\FileFinder;$finder = FileFinder::create()
->files()
->name('*.php')
// ->ignoreVCS(false)
// ->ignoreDotFiles(false)
// ->exclude('tmp')
->notPath('tmp')
->inDir(dirname(__DIR__));foreach ($finder as $file) {
// var_dump($file);
echo "+ {$file->getPathname()}\n";
}
```## File Tree Builder
`FileTreeBuilder` - can be quickly create dirs and files, copy dir and files.
- can use path var in `dir()`, `copy()` ... methods. eg: `copy('{baseDir}/to/file', '{workdir}/dst/file')`
Quick start:
```php
use Toolkit\FsUtil\Extra\FileTreeBuilder;$ftb = FileTreeBuilder::new()
->setWorkdir($workDir)
->setShowMsg(true);// copy dir to $workDir and with exclude match.
$ftb->copyDir('/path/to/dir', './', ['exclude' => ['*.tpl']])
->copy('/tplDir/some.file', 'new-file.txt') // copy file to $workDir/new-file.txt
// make new dir $workDir/new-dir
->dir('new-dir', function (FileTreeBuilder $ftb) {
$ftb->file('sub-file.txt') // create file on $workDir/new-dir
->dirs('sub-dir1', 'sub-dir2'); // make dirs on $workDir/new-dir
})
->file('new-file1.md', 'contents'); // create file on $workDir
```Will create file tree like:
```text
./
|-- new-file.txt
|-- new-dir/
|-- sub-file.txt
|-- sub-dir1/
|-- sub-dir2/
|-- new-file1.md
```### path vars
- `tplDir` The template dir path
- `baseDir` base workdir path, only init on first set workdir.
- `current,workdir` current workdir path.
- And all simple type var in `tplVars`.Usage in path string: `{baseDir}/file`
## Modify Watcher
```php
use Toolkit\FsUtil\Extra\ModifyWatcher;$w = new ModifyWatcher();
$ret = $w
// ->setIdFile(__DIR__ . '/tmp/dir.id')
->watch(dirname(__DIR__))
->isChanged();// d41d8cd98f00b204e9800998ecf8427e
// current file: ae4464472e898ba0bba8dc7302b157c0
var_dump($ret, $mw->getDirMd5(), $mw->getFileCounter());
```## License
MIT