You are not logged in.

#1 2012-03-21 14:38:53

jjacky
Member
Registered: 2011-11-09
Posts: 347
Website

molt: batch renaming utility

Hi all,

Recently I was looking for a batch renaming utility, and while I did find a few, none of them would really fill all the checkboxes of my requirements list. Either because they didn’t provide the "rules" I was looking for, or because they would rename files after each rule has been applied, or because they couldn’t be used from scripts (that way I wanted), or whatever the reason. So I made myself one: molt.

You use it by specifying a set of rules to use, which will all be processed to determine the new name. molt will make sure those new names are "free," as in not already in use; and handles "avoidable conflicts" - when a file's new name is taken by another file to be renamed (performing two-steps renaming with a temporary name if needed).

Usage: molt [OPTION]... RULE... [FILE]...

	Options :
 -D, --exclude-directories    Ignore directories from specified files
 -F, --exclude-files          Ignore files from specified files
 -S, --exclude-symlinks       Ignore symlinks from specified files
 -i, --from-stdin             Get list of files from stdin
 -P, --process-fullname       Send the full path/name to the rules
                               (Imply --output-fullname)
 -p, --allow-path             Allow (relative/absolute) paths in new filenames
                               (Imply --output-fullname)
 -m, --make-parents           Create parents if needed
 -O, --output-fullname        Output full path/names
 -B, --output-both-names      Output the old then the new filename for each file
 -N, --output-new-names       Output the new filename for each file
 -R, --only-rules             Only apply the rules and output results,
                               without any conflict detection
                               (Imply --dry-run)
 -n, --dry-run                Do not rename anything
 -C, --continue-on-error      Process as much as possible, even on errors
                               or when conflicts are detected
 -d, --debug                  Enable debug mode - Specify twice for verbose
                               output
 -h, --help                   Show this help screen and exit - Specify twice for
                               verbose output
 -V, --version                Show version information and exit

	Rules :
Rules are the part of molt that process filenames. Rules will be applied
in the order specified, you can use the same rule as may times as you want.
Some rules require a parameter, what it can be depend of the rule. Usually,
it will be a string where you can specify multiple parameter using slash ( / )
as separator.

 --upper                      Convert to uppercase
 --lower                      Convert to lowercase
 --vars                       Resolve variables
 --tpl PARAM                  Apply specified template (resolve variables)
 --sr PARAM                   Search & replace a string
   PARAM = search[/replacement[/option]]
   If no replacement is specified, the string will be removed.
   Search is case-sensitive, unless option i was specified.

 --camel                      Convert to Camel Case
 --list                       Use list of new names from stdin
 --regex PARAM                Search & replace using regular expression
   PARAM = pattern[/replacement[/option]]
   If no replacement is specified, the string will be removed.
   Search is case-sensitive, unless option i was specified.


	Variables :
You can use variables in the new filenames. The syntax is to put the
variable's name in between dollar signs, e.g: $FOOBAR$
You can also (if supported) specify one (or more) parameters, using colon
as separator, e.g: $FOOBAR:PARAM1:PARAM2$
Variables are not automatically resolved, you need to use the rule --vars
in order to have them resolved, which gives you the ability to determine
when resolving happens, and continue processing with more rules afterwards.
Note that rule --tpl also resolves variables.

 NB[:PARAM...]                Counter, incremented for each file using it
   You can specify up to 3 parameters:
   - the minimum number number of digits (padding with 0's)
   - the starting value of the counter
   - the increment (can be negative)
   E.g: $NB:3:42:-2$ will resolve as 042, 040, 038, etc

 _[:PARAM...]                 Magic variable: specify "variable" as parameter
   The first parameter is the name of the "variable" to resolve.
   Resolving is done running the corresponding command line, using output
   as value (removing trailing newline (\n) if present)

Links:
- Slightly more verbose description
- Source code
- PKGBUILD in the AUR

Hopefully someone may find it useful.

Cheers,
-jacky

Offline

Board footer

Powered by FluxBB