Nora is a command line utility for renaming files in batch using regex with advanced control. It is using a custom language created only for this purpose. Any suggestion is appricated (using github issues)
Comming soon
Command line usage
nora [OPTIONS] <INPUT> <OUTPUT>
| commands | description |
| ------------------------ | --------------------------------------------------- |
| -h
\| --help
| Print help information |
| -s
\| --skip
| Skip the renaming preview and directly rename files |
| -V
\| --version
| Print version information |
| -p
\| --pretty_print
| Pretty print the output for easier reading |
Input is a regex expression. Capture groups can be used (see here for using them in the output)
Named Captrure groups also works (see here for using them in the output)
The output expression is a little language easy to use
Two concepts are important, the unvariable parts and the interpreted parts
The unvariable part won't change when renaming while anything in the interpreted blocks will be interpreted considering this example:
[#1].txt
The unvariable part is the .txt
An interpreted block starts with [
and ends with ]
in this case the interpreted block is [#1]
which contains #1
The interpreted block can have the following expressions
Example:
[#1 == 10 ? 1 : 2]
Dependant on the condition, if it's true 1 will be returned otherwise 2 will be returned
The condition operator can be any of these ==
, !=
, <
, <=
, >
, >=
If you you want to do a ternary as a normal if statement to write something if it's true but nothing if not Example:
[#1 == 10 ? "something" : ""]
The skip operator can be used to simplify this Example:
[#1 == 10 ?> "something"]
Example:
[10 + 20]
currently supported operations are +
, -
, *
, /
, **
, //
, (
, )
**
: Power opertaor
//
: Log operator
It is important to note that math expressions will only be interpreted as mathematical expressions when the left paramter is a number (like JavaScript would)
For example:
["10" + 20]
This will give 1020 since it will convert the left to a string and do a concatenation
[10 + "20"]
This will give 30 since the left is a number and it will convert to string to a number automatically
Example:
["hello " + "world"]
It is important to note that concatenation of strings will only occur when the left paramter is a string (like JavaScript would)
For example:
["10" + 20]
This will give 1020 since it will convert the left to a string and do a concatenation
[10 + "20"]
This will give 30 since the left is a number and it will convert to string to a number automatically
Example:
["testes" - "te"]
This will give the ouput stes
which removes the first te
found
Example:
["testes" -- "te"]
This will give the ouput ss
which removes all te
found
Identifers are variables from the interpreter and the regex Example:
[#1]
[foo]
[bar]
[#count]
These are all variables
variables starting with #
are reserved for the interpreted (this means your capture groups shouldn't start with #
)
when using a regex, the capture groups can be used in interpreted block like the following
[#0]
[#1]
...
[#n]
The number represent the capture groups in order.
it is important to note that #0
the whole regex capture so the first capture group is #1
Using the named capture groups is similar to the normal capture group. The only difference is to ommit the #
at the start
For example, if a named capture group is test
it will be used as follows
[test]
Import Note: When using any capture group or named capture group identifiers, they are all strings by default.
To use mathematical expression when they are the left parameter of tha math epxression it is nessecary to convert them to numbers
Example:
[string(#1)]
Transform the expression between the parenthese to a string
Example:
[number(#1)]
Transform the expression between the parenthese to a number
Rename files from (number).txt to (number).mkv
nora '(\d+)\..*' '[#1].mkv'
Rename files from (number).txt to (number + 10).txt
nora '(\d+)\..*' '[number(#1) + 10].txt'
Rename files from (number>.txt to (number + 10).txt only if (number) is 0 if not leave it as (number).txt
nora '(\d+)\..*' '[#1 == 0 ? number(#1) + 10 : #1].txt'