Releases: jericirenej/batch-rename
Releases · jericirenej/batch-rename
v1.0.2
v1.0.1.
Changelog
- Ensure that program exits, if a utility action is chosen (
restoreorcleanRollback). - Update tests.
- Dependencies version bump.
Full Changelog: v1.0.0...v1.0.1
v1.0.0
README Extract
Usage guide
- One of the valid transform types must be provided (
numericTransform, searchAndReplace, dateTransform, keep, omit, truncate, format, addText), together with other optional arguments. - Alternatively, a rollback operation may be perform by supplying the appropriate option.
- Running script with no arguments will show the help menu and exit.
When performing the rename operation, the script will write a restore file (.rollback.json) to the target folder (except if --skipRollback flag is set). Without this file, restore operations are not possible.
Dry run is enabled by default. This means that planned changes will be displayed and executed only after explicitly confirming them. It is strongly encouraged not to disable the dry run mode.
The script will not perform a rename if it would lead to name collisions (i.e. several files sharing the same name).
Options overview
| Flag | Arguments | Description |
|---|---|---|
-n, -numericTransform |
[sequential | even | odd] |
Rename files by using either a sequence (n+1), even (2n), or odd (2n+1) numbering algorithm. Defaults to sequence. To help with file-sorting, the number of digits will always be one more than the number taken up by the total count of target files (a list of 10 files is represented by two digits - therefore, three digits will be used: 001, 002 ...). |
-d --dateRename |
<creationDate, lastAccessed, lastModified> |
Use date-related file information to rename a file. Defaults to creationDate. Can be used together wit the --detailedDate flag to add time information. |
-s, --searchAndReplace |
<string|regex> <replacer> |
Takes a string or a regex filter argument and a replacer string. By default, the transform will preserve file extensions, unless a --noPreserveExtension option is supplied. |
-k --keep |
<regex|string> |
Will remove everything, except the matched part of the name. Essentially the same as replacing positive look-behind and look-ahead captures and with empty strings. Can be used together with addText, textPosition, format, noExtensionPreserve, and separator flags. |
-o --omit |
<regex|string> |
Will remove all matched parts of the name. Can be used together with addText, textPosition, format, noExtensionPreserve, and separator flags. |
-t, --truncate |
<number> |
Truncate the baseName. Can be used in combination with other transform types or on its own. If used on its own, and preserveOriginal is false, it has no effect. |
-f, --format |
[uppercase | lowercase | capitalize] |
Perform one of the specified transformations on the final rename. Can be used in conjunction with other transforms (except extensionModify). |
-a, --addText |
<string> |
Text to add to the target filename. Can be used on its own, together with 'textPosition' flag, or in combination with other transform types. Overwrites the preserveOriginal flag. |
-e, --extensionModify |
<string> |
Modify extension of target files. Can also be used together with the exclude option. |
--target |
<path> |
Folder in which the transformation should take place. Can also be set implicitly with an extra script argument (explicit setting takes precedence). If omitted, the script defaults to current working directory. |
--targetType |
['files'|'dirs'|'all'] |
Determine which file types should be included in transform. Defaults to 'files' if omitted or supplied without option. |
-r, --restore |
[number] |
Restore transformed files to target rollback level. If no level is provided, maximum restore level will be used. |
-D, --dryRun |
<boolean> |
Log expected output and write only after confirmation. Defaults to true. |
-b, --baseIndex |
<number> |
For numeric transform, optional argument to specify the base index from which the sequencing will begin. |
--exclude |
<string|regex> |
Preemptively exclude files that match a given string or regular expression from being evaluated in the transform functions |
-p, --preserveOriginal |
[boolean] |
Preserve original file name. Not relevant for the searchAndReplace transform type. Defaults to true. |
--noExtensionPreserve |
An option for the searchAndReplace and format transforms which includes the file extension in the transform operation. |
|
--textPosition |
[prepend | append] |
Applies to preserveOriginal or addText. Specifies where original or custom text should be appended with respect to the transformation text. Defaults to append. |
--detailedDate |
Appends time information (T hh:mm:ss) to date transformations. |
|
--separator |
<character> |
Specify a custom character which will be used as a separator the original | custom text and the transform text. Can be an empty string (in this case it will be ignored in date formatting). Defaults to hyphen (-). |
--skipRollback |
[boolean] |
Skip writing transform details to rollback file. Defaults to true, if omitted. |
--cleanRollback |
[boolean] |
Remove rollback file. |
-h, --help |
Show help. | |
-V, --version |
Output the version number. |
CAUTION | DISCLAIMER:
Performing renaming operations on files is not without risks. Things can go wrong, errors can happen, rollbacks might not succeed, data might be lost. So remember:
- Perform renaming operations only on files that you are prepared to lose or have backed up.
- Default dry runs are enabled for a reason.
- This script doesn't give you any guarantees or warranties about anything.