COMMAND SYNTAX


Overview

The syntax of the commands that SRename understands is relatively straightforward. After giving the filename(s) or file pattern(s) to rename you simply supply an action that will modify those filenames or patterns.
If you don't want to modify the entire filename but only a part of it you must also supply one or more selectors before that action.
If you want to modify the filename in a somewhat complex way you will have to give more than one action. In that case it makes sense that each action should modify a different part of the filename otherwise each action would overwrite the previous one. So to do that selectors have to be given before each action.

So basically the command syntax looks like this (brackets indicate optional arguments) :

FILENAME(S) or FILEPATTERN(S) [SELECTOR(S)] ACTION [SELECTOR(S)] ACTION [SELECTOR(S)] ACTION .....

After each action is executed the selectors are cleared so they have to be given again for the next action. If no selectors are given before an action then the whole filename is modified.

For example: SRename ram:anyfile LOWER LEFT 1 UPPER RIGHT 1 UPPER
Here "LOWER" makes the whole filename lowercase because no selector is given before it, and then the first and last characters are made uppercase with "LEFT 1 UPPER" and "RIGHT 1 UPPER".

There are a number of general options that SRename also accepts and these can be placed anywhere in the command line but for the sake of clarity it's better to put them at the beginning. These general options affect every selector and action that will be performed and should only be given once in the command line.
There are also some options that affect selectors and some options that affect actions. Selector options should be placed before the selectors of each action, with the exception of INVERTSEL that should be placed after the selectors, and action options should be placed after each action.
Finally some selectors and actions accept secondary arguments that should be placed immediately after those selector and actions.

Taking all those details into account the command syntax looks like:

FILENAME(S) or FILEPATERN(S) [GENERAL OPTIONS] [SELECTOR OPTIONS] [SELECTOR & SECONDARY ARGUMENTS] [SELECTOR & SECONDARY ARGUMENTS] ACTION [ACTION OPTIONS] ... more selectors and actions...
 
Example of such a command line:
SRename sys:a#? ram:#?s ALL FILES PREFIRST PREFIX MATCH mod CASESENS LEFT 1 UPPER TOCOMMENT ... more selectors and actions...

In this example "ALL" and "FILES" are general options, "PREFIRST" is a selector option, "PREFIX", "MATCH mod" and "LEFT 1" are selectors, "CASESENS" is a secondary argument to "MATCH mod", "UPPER" is an action, and "TOCOMMENT" is an action option.



Details

Selectors and Actions can be given multiple times in the command line, but Renumbering Selectors and Actions can only be given once, because currently SRename doesn't support multiple renumbering actions of the same type at the same time in the command line.
Because of this the order that Renumbering Options, Selectors and Actions are given doesn't matter, but for the sake of consistency it's better to give Renumbering commands in the same way that the other commands are given:
Renumbering Options first, then Renumbering Selectors and Renumbering Actions last.

The order that selectors are given is not important right now because the order that they are evaluated is fixed.
That may change in the future however and in order to maintain command interface compatibility in future versions, it is recommended that you give selectors in the command line in the order that they are evaluated.
That order is:

COMMENT (CO)
PREFIX (PR)
MAIN (MA)
SUFFIX (SU)
WORD (WD)
MATCH (MT)
LEFT (L) *
MID (M) *
RIGHT (R) *

*
Can use only one of those selectors for each action.

This fixed order of evaluation mean that you can select for example the suffix, then a word in suffix, then match a string in the word and then select the leftmost character in that string, but you can't for example select the 10 leftmost characters and then match a string in those, because MATCH will be evaluated before LEFT.

And of course you can't use the same selector more than once for each action. For example you can't select the 10 leftmost characters and then the 3 leftmost characters of those 10 characters.

Because the PREFIX, MAIN and SUFFIX selectors can be used all at once with the same action, every selector that will be given after these 3 selectors and the action that uses them, will be repeated for each prefix, main and suffix components of the filename.
For example if "MAIN SUFFIX MATCH document LEFT 1 UP" is used then SRename will try to match the string "document" and select it's first character, for both the main and the suffix components.

The order that actions are given matters because the filename is modified immediately after each action is executed. Because of this what will be selected and modified by one action depends on what was modified by a previous action, if more than one action was given.
For example if we have a filename like "modtestsound" and we want to swap "mod" and "sound" with each other so that we will have "soundtestmod", we can't do that yet by replacing "mod" with "sound" and then replacing "sound" with "mod" because such an operation would require that the filename wouldn't be modified immediately after each action.
Such a "cached" mode of operation will be implemented in the next version.

Finally the order that secondary arguments are given after a selector or action doesn't matter as soon as those secondary arguments are given immediately after the relevant selector or action. For example "MATCH abcd DO 1 SKIP 1 REVMATCH" and "MATCH abcd SKIP 1 REVMATCH DO 1" do the same thing.