Examples

Here are some detailed examples that should help you to write rename expressions.





Rename an image with the date and time it has been taken

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_givesPlanet_Mars_
Planet_Mars_%XdogivesPlanet_Mars_20030909_214758
Planet_Mars_%Xdo.jpggivesPlanet_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



Append a date following the format you've chosen

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 :

%bgivesNote
%b-givesNote-
%b-%dm{"%m-%d-%y"}givesNote-01-02-03
%b-%dm{"%m-%d-%y"}.%egivesNote-01-02-03.txt

Related information : dates



Move images following the date they have been taken


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" :


Related information : dates



Names with numbers of different sizes

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_%Ngives"Img_002"
Img_%N.gives"Img_002."
Img_%N.%egives"Img_002.jpg"

Add a value to numbers

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" :

Imggives"Img"
Img%Ngives"Img50"
Img%N{1,5}gives"Img55"
Img%N{1,5}.gives"Img55."
Img%N{1,5}.%egives"Img55.jpg"

Change the case (upper-case/lower-case)

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 :

%fgivesSONG TITLE.MP3
%LfgivesSong title.mp3

Related information : case modification



Replace the '.' (dots) with ' ' (spaces)

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 :

%bgivesMy.preferred.movie
%b("."," ")givesMy preferred movie
%b("."," ").givesMy preferred movie.
%b("."," ").%egivesMy preferred movie.avi

Related information : string replacement



Extract only the end of a string

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" :

%fgivesA1B#0302.gif
%f(-8)gives0302.gif

Related information : string extraction



Extract only the beginning of a string

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" :

%bgivesA1B#0302
%b(1,-5)givesA1B
%b(1,-5).givesA1B.
%b(1,-5).%egivesA1B.gif

Related information : string extraction



Invert parts, delete some

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 :

%bgivesSong Title 1 - Singer - Site
%b[1]givesSong Title 1
%b[2]givesSinger
%b[3]givesSite

If the index is negative, the numbering starts from the end :

%b[-1]givesSite
%b[-2]givesSinger
%b[-3]givesSong Title 1

%e, the file extension is "mp3"

So, following the expression on "Song Title 1 - Singer - Site.mp3" :

%b[2]givesSinger
%b[2] -givesSinger -
%b[2] - %b[1]givesSinger - Song Title 1
%b[2] - %b[1].givesSinger - Song Title 1.
%b[2] - %b[1].%egivesSinger - Song Title 1.mp3

Related information : "[]" modifier



Array extraction with elements separated with strings

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 :

%bgivesArtist =##= Album =##= Song
%b("=##=","-")givesArtist - Album - Song
%b("=##=","-")[3]givesSong
%b("=##=","-")[3].givesSong.
%b("=##=","-")[3].%egivesSong.mp3

Related information : string replacement, "[]" modifier



The "The" problem

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]givesThe Beatles
%b[1](5)givesBeatles
%b[1](5), The -givesBeatles, The -
%b[1](5), The - %b[2]givesBeatles, The - Eleanor Rigby
%b[1](5), The - %b[2].givesBeatles, The - Eleanor Rigby.
%b[1](5), The - %b[2].%egivesBeatles, The - Eleanor Rigby.mp3

Related information : "[]" modifier, string extraction



Delete the beginning of a string until a given character

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" :

%fgivesGood - Singer - Title 1.mp3
%f[2,0,"-"]givesSinger - Title 1.mp3

Here is another solution : %b("-","*",1,1)[2,"*"].%e

Related information : "[]" modifier



Delete a "delimited" substring

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" :

%fgivesTitle 1 (www.site.net) Singer 1.mp3
%f[1,"("]givesTitle 1
%f[1,"("] -givesTitle 1 -
%f[1,"("] - %f[-1,")"]givesTitle 1 - Singer 1.mp3

Related information : "[]" modifier



Regular expressions

I won't enter here into the details of the syntax.



Related information : regular expression



Rename associated files

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>bgivesFi1-A
%<2,1>b.givesFi1-A.
%<2,1>b.%egivesFi1-A.srt

Related information : group renaming



Rename associated files while renumbering them

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.JPGIMG_3975.RAWPIC10222.JPGPIC10222.RAW
%e-Img_%nc.%eJPG-Img_001.JPGJPG-Img_001.RAWJPG-Img_002.JPGRAW-Img_002.RAW
%f[2]Img_001.JPGImg_001.RAWImg_002.JPGImg_002.RAW

Related information : sub-expressions, "[]" modifier



Rename with Roman numerals

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 :

%bgivesDOCUMENT
%b - givesDOCUMENT -
%b - %T{"C:\\romnum.txt"}givesDOCUMENT - IV
%b - %T{"C:\\romnum.txt"}.givesDOCUMENT - IV.
%b - %T{"C:\\romnum.txt"}.%egivesDOCUMENT - IV.odt

Related information : "%T" variable



Default examples

The first time you start Siren (in fact during the the creation of configuration file) examples are added in the "Favourites" and "Tools" menus.