PHP code example of toolkit / fsutil

1. Go to this page and download the library: Download toolkit/fsutil library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

toolkit / fsutil example snippets


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";
}

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

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());