Here are some detailed examples that should help you to write rename expressions.
How does it work ?
Most part of digital cameras adds in the image many data concerning the shot. Among those, several dates with one at which
the image was taken.
Siren extracts this information and makes it directly usable in an expression through the variable :
%Xdo (eXif DatetimeOriginal)
By default it follows the format : YYYYMMDD_HHMMSS
So, following the expression for "IMG_3975.JPG" :
Planet_Mars_ gives Planet_Mars_ Planet_Mars_%Xdo gives Planet_Mars_20030909_214758 Planet_Mars_%Xdo.jpg gives Planet_Mars_20030909_214758.jpg
And if images were taken in the same second ?
With the above expression some "new names" will be identical, therefore an error will appear during the renaming.
The variables "%nc" and "%ncs" give a unique value avoiding name "collisions".
You can use an expression like : Planet_Mars_%Xdo%ncs.jpg
Let's take the file "Note.txt" modified the 01/02/2003
How does it work ?
The most elegant solution seems to be the one using a date format modifier.
A date format is a character string explaining which elements to extract from it and how to put them together.
In our case, it's the day, month and year (without the century) separated by '-'.
%d : corresponds to the day
%m : the month
%y : the year on two digits
So, the format string we are interested in is : %m-%d-%y
A date format has to be specified between braces just after the name of the variable.
%b corresponds to the file base name, in our case : "Note"
%dm corresponds to the last modification date
%e, the file extension is "txt"
So, following the expression :
%b gives Note %b- gives Note- %b-%dm{"%m-%d-%y"} gives Note-01-02-03 %b-%dm{"%m-%d-%y"}.%e gives Note-01-02-03.txt
Related information : dates
How does it work ? (explanations useful only for Windows users)
If Siren can rename files, it can also move them and create the missing directories.
The first thing that can be surprising are the doubled '\'. It's normal, '\' is an
escape character (it makes loose the "special" status to its following character) so
to appear as itself it has to remove himself its "special" status ...
We have already seen how to change the format of a date.
By separating the year, month and day elements with '\' (or '/' under GNU/Linux) it becomes a file path.
So, following the expression on "IMG_3975.JPG" :
C:\\Photo\\ | gives | C:\Photo\ | ||
C:\\Photo\\%Xdo{"%Y\\%m\\%d"} | gives | C:\Photo\2003\09\09 | ||
C:\\Photo\\%Xdo{"%Y\\%m\\%d"}\\%b.%le | gives | C:\Photo\2003\09\09\IMG_3975.jpg |
/home/user/Photo/ | gives | /home/user/Photo/ | ||
/home/user/Photo/%Xdo{"%Y/%m/%d"} | gives | /home/user/Photo/2003/09/09 | ||
/home/user/Photo/%Xdo{"%Y/%m/%d"}/%b.%le | gives | /home/user/Photo/2003/09/09/IMG_3975.jpg |
Related information : dates
How does it work ?
This is annoying because alphabetically "Img2.jpg" comes after "Img10.jpg".
%N is a variable that will contain the first number of the base name of the file.
For "Img2.jpg", %N will contain 2. In fact it will contain "002" or "02" ...
depending on the size defined in "Preferences/New name computation/Numbers" or in the expression
(click here for more details).
%e, the file extension is "jpg"
So, following the expression for "Img2.jpg" :
Img_ gives "Img_" Img_%N gives "Img_002" Img_%N. gives "Img_002." Img_%N.%e gives "Img_002.jpg"
How does it work ?
The %N variable can be followed by a specific modifier that will change its default
parameters (click here for more details).
In this case the first number in the base name is extracted, no zeroes are added to its left (1) and
5 is added to it (-5 would have substract 5).
%e, the file extension is "jpg"
So, following the expression for "Img50.jpg" :
Img gives "Img" Img%N gives "Img50" Img%N{1,5} gives "Img55" Img%N{1,5}. gives "Img55." Img%N{1,5}.%e gives "Img55.jpg"
How does it work ?
Between the character '%' and the name of the variable you can add a case modifier (upper/lower).
It only modifies the string it is associated to. Four exist. Among them : 'L' sets the first
character upper-case and the rest lower-case.
%f represents the full name of the file.
So, following the expression :
%f gives SONG TITLE.MP3 %Lf gives Song title.mp3
Related information : case modification
How does it work ?
Here, we use the replacement modifier with two parameters, the string to replace and the replacement string.
We want to substitute all the '.' with ' ', so the first will be '.' and the second ' '.
We apply this modifier on "%b" which is the base name (file name without extension).
Applying it on "%f" (full name), we would have replaced the '.' just before the extension.
%e, the file extension is "avi"
So, following the expression :
%b gives My.preferred.movie %b("."," ") gives My preferred movie %b("."," "). gives My preferred movie. %b("."," ").%e gives My preferred movie.avi
Related information : string replacement
How does it work ?
The "()" modifier permits the extraction of a part of the string it is associated to.
Its first parameter is the starting position of this extraction, an optional second
parameter specifies the number of characters to extract. If it's not given, the
extraction is done until the end.
Which value to choose as starting position ?
It depends on the file we examine. 10 for the first and 5 for the second ... In fact,
we only need the last 8 characters. It would be interesting to specify that the
number of the first character to extract is relative to the end and not the
beginning of the string. Siren manages this with "negative" numbers.
For example, with "ABCDEF" :
More clearly, -8 "alone" will specify : "the 8 last characters"
%f is the full file name
So, following the expression for "A1B#0302.gif" :
%f gives A1B#0302.gif %f(-8) gives 0302.gif
Related information : string extraction
How does it work ?
As we previously saw, the "()" modifier permits to define a start of extraction
relative to the end of a string.
The problem here is slightly different because this time it's the number of
characters that must be relative to the length of the string.
If you give to "number of characters" (2nd parameter) a negative value, the position
of the last extracted character will be computed this way :
length of the string minus the absolute value of the parameter.
In our case, "%b" is :
%b(1,-5) will be equivalent to :
%e is the file extension
So, following the expression for "A1B#0302.gif" :
%b gives A1B#0302 %b(1,-5) gives A1B %b(1,-5). gives A1B. %b(1,-5).%e gives A1B.gif
Related information : string extraction
How does it work ?
The "[]" modifier "splits" the associated string in array elements following
the characters specified in "Preferences/New name computation/Array elements separators"
(or given as second parameter to "[]").
Each "substring" is reachable through its index.
In this case, if '-' is one of the separators :
%b gives Song Title 1 - Singer - Site %b[1] gives Song Title 1 %b[2] gives Singer %b[3] gives Site
If the index is negative, the numbering starts from the end :
%b[-1] gives Site %b[-2] gives Singer %b[-3] gives Song Title 1
%e, the file extension is "mp3"
So, following the expression on "Song Title 1 - Singer - Site.mp3" :
%b[2] gives Singer %b[2] - gives Singer - %b[2] - %b[1] gives Singer - Song Title 1 %b[2] - %b[1]. gives Singer - Song Title 1. %b[2] - %b[1].%e gives Singer - Song Title 1.mp3
Related information : "[]" modifier
How does it work ?
It's clear that we have to use the array extraction (especially if we've have
many files to rename).
But ... the different elements are separated with strings and not only one character
(that we could add in "Preferences/New name computation/Array elements separators"
or pass as second parameter to "[]").
The "simple" idea consists to "concatenate" the modifiers, each is applied on the
preceding result. By replacing "=##=" with a '-' we can use without problem the "[]" modifier.
In the preceding examples we have already made replacements.
%e, the file extension is "mp3"
So, following the expression :
%b gives Artist =##= Album =##= Song %b("=##=","-") gives Artist - Album - Song %b("=##=","-")[3] gives Song %b("=##=","-")[3]. gives Song. %b("=##=","-")[3].%e gives Song.mp3
Related information : string replacement, "[]" modifier
Imagine you've got many "mp3" files whose file names are formatted this way : Artist - Song.mp3
If you've correctly named your "Beatles" files, they begin with "The Beatles". But you may
have prefer something else : "The Beatles" should have been listed in the 'B' rather the 'T'.
How does it work ?
We use there a combination of the extracts by array and position.
With the file : The Beatles - Eleanor Rigby.mp3
%b[1] gives "The Beatles" and %b[2] gives "Eleanor Rigby
The following modifier : "(5)" makes an extraction on the string it is associated to,
in this case : "%b[1]" so "The Beatles". The number 5 gives the starting position,
the absence of a second parameter signifies that the extraction is done until the end.
So %b[1](5) ("The Beatles") from 5th character, gives "Beatles".
%b[2] gives "Eleanor Rigby"
%e, the file extension is "mp3"
So, following the expression on "The Beatles - Eleanor Rigby.mp3" :
%b[1] gives The Beatles %b[1](5) gives Beatles %b[1](5), The - gives Beatles, The - %b[1](5), The - %b[2] gives Beatles, The - Eleanor Rigby %b[1](5), The - %b[2]. gives Beatles, The - Eleanor Rigby. %b[1](5), The - %b[2].%e gives Beatles, The - Eleanor Rigby.mp3
Related information : "[]" modifier, string extraction
How does it work ?
The idea is to use the "[]" modifier.
If the string is split in parts around "-", we want all of the elements starting at the second one.
0 : indicates that the number is "as much as possible".
So, following the expression on "Good - Singer - Title 1.mp3" :
%f gives Good - Singer - Title 1.mp3 %f[2,0,"-"] gives Singer - Title 1.mp3
Here is another solution : %b("-","*",1,1)[2,"*"].%e
Related information : "[]" modifier
How does it work ?
The idea is to see '(' and ')' as array element separators. The extraction modifier
"[]" allows a second parameter that gives a list of separator characters (it replaces
the default one defined in "Preferences/New name computation/Array elements separators").
Why use "-1" as number for the second extraction ?
In principle, we don't know the number of ')'.
"-1" will return the first element starting from the end : the string following the last ')'.
So, following the expression on
"Title 1 (www.site.net) Singer 1.mp3" :
%f gives Title 1 (www.site.net) Singer 1.mp3 %f[1,"("] gives Title 1 %f[1,"("] - gives Title 1 - %f[1,"("] - %f[-1,")"] gives Title 1 - Singer 1.mp3
Related information : "[]" modifier
I won't enter here into the details of the syntax.
Related information : regular expression
Some file types can be "associated". It is the case, for example, for ".srt" with ".avi", ".thm" with ".crw", ".h" with ".cpp" etc. Only the extension changes, the base name remains the same.
Here is a relatively simple method to realize a renaming achieving this "synchronisation".
Fi1-A.avi, Fi2-B.avi and Fi3-C.avi will be our "source" files.
How does it work ?
We have to replace the "srt" files base names with the ones of their associated "avi".
To achieve this we are going to use the group renaming modifier.
In our example each group will be composed of two files : an "avi" and its "srt". We choose to select the "avi" first and then the "srt". So, the "avi" will be the first member of the group and the "srt" the second.
Getting the base name of an "avi" in an expression can be done with : %<2,1>b
%e is the file extension of the file currently treated.
The "avi" new names will be identical to the current ones. So for them, no change will be done during the renaming.
So, following the expression on "1.srt" :
%<2,1>b gives Fi1-A %<2,1>b. gives Fi1-A. %<2,1>b.%e gives Fi1-A.srt
Related information : group renaming
How does it work ?
An rename expression can be compound of "sub-expressions" separated by ';' (semicolon).
They are evaluated one after another on all the files. Of course, from the second one
all the variables normally associated to the "Current name" (%f, %e, %N ...) will be
related to the "New name" computed by the previous one.
Why adding "%e" at the beginning of the name and remove it just after ?
"%nc" gives a number avoiding collisions without taking into account the following rest of the expression. In our example the extension has to be part of the collision evaluation. By creating a temporary one, we will get the expected result.
So, following the expression :
IMG_3975.JPG | IMG_3975.RAW | PIC10222.JPG | PIC10222.RAW | |||||
%e-Img_%nc.%e | JPG-Img_001.JPG | JPG-Img_001.RAW | JPG-Img_002.JPG | RAW-Img_002.RAW | ||||
%f[2] | Img_001.JPG | Img_001.RAW | Img_002.JPG | Img_002.RAW |
Related information : sub-expressions, "[]" modifier
You may want to add the selection number to your file names but instead of Arabic numerals you want to use Roman ones or any other translation or character sequence.
How does it work ?
As explained here, the "%T" variable extracts lines from a text file which name
is given to it as parameter. For each selected file, the line extracted is the one corresponding to its selection number.
So, if we fill the "C:\romnum.txt" file with the lines :
I
II
III
IV
V
VI
...
Then %T{"C:\\romnum.txt"} will be evaluated to "I" for the first file, to "II" for the second file,
"IV" for the fourth one etc.. Indirectly the Arabic numerals will be converted to Roman ones.
So, following the expression on "DOCUMENT.odt" being the fourth selected file :
%b gives DOCUMENT %b - gives DOCUMENT - %b - %T{"C:\\romnum.txt"} gives DOCUMENT - IV %b - %T{"C:\\romnum.txt"}. gives DOCUMENT - IV. %b - %T{"C:\\romnum.txt"}.%e gives DOCUMENT - IV.odt
Related information : "%T" variable
The first time you start Siren (in fact during the the creation of configuration file) examples are added in the "Favourites" and "Tools" menus.