toolkit / fsutil
some file system tool library of the php
Installs: 5 662
Dependents: 4
Suggesters: 0
Security: 0
Stars: 5
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: >=8.0.1
- toolkit/stdlib: ^2.0
Suggests
- inhere/console: a lightweight php console application library.
- inhere/php-validate: Very lightweight data validate tool
README
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+
composer require toolkit/fsutil
File Finder
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:
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:
./
|-- new-file.txt
|-- new-dir/
|-- sub-file.txt
|-- sub-dir1/
|-- sub-dir2/
|-- new-file1.md
path vars
tplDir
The template dir pathbaseDir
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
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