A collection of file system utilities.
- (There are no tagged releases yet)
- Download a PHAR from the latest releases tab here on Github.
- Put it somewhere in PATH.
-
Build the PHAR
$ composer require bobmagicii/fileutil
$ fileutil phar
$ php bin\fileutil.php phar -
Put the
build/fileutil.pharsomewhere in PATH.
$ composer require bobmagicii/fileutilWindows Nice Mode
C:\Users\bob\Videos> fileutil cleanup strip-sitenamesWindows Lazy Mode
C:\Users\bob\Videos> php C:\Local\Tools\fileutil.phar cleanup strip-sitenamesIn the above situation fileutil is a bat file sitting next to the phar file in the directory C:\Local\Tools which is in my shell PATH. That is what makes the magic invokation work. Otherwise you will likely have to do something like the second choice.
C:\Local\Tools\fileutil.batC:\Local\Tools\fileutil.phar
It will search the directory that it is working on as well as a directory called fileutil sitting next to the Phar.
C:\Users\bob\Videos\strip-sitenames.jsonC:\Local\Tools\fileutil\strip-sitenames.json
Optionally a directory may be specified after the ruleset name otherwise it will work upon the current working directory. The default is to do a dry run to inspect what it wants to do. Add the --commit option to make it go brrrrrt.
The following JSON placed in a file called toggle.json will cause files named omg1.txt to omg9.txt to be renamed with a prefix of bbq and running it again will send them back.
These CleanupRule are Regular Expression formatting rules where if the file name matches the Find expression it will be renamed to fit the Format pattern. Groups from the regex can be used with the tokens {%1%} where the number is the group number.
{
"Cleanup": [
{
"Type": "regfmt",
"Find": "#^omg(\\d)\\.(txt)#",
"Format": "bbq{%1%}.{%2%}"
},
{
"Type": "regfmt",
"Find": "#^bbq(\\d)\\.(txt)#",
"Format": "omg{%1%}.{%2%}"
}
]
}If you have the source code repo then this is one of the tests that can be ran. Watch the files in the tests\set1 folder while running this a few times to see them flip flop:
$ fileutil cleanup toggle tests\set1 --commit