### 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
- Append a date following the format you've chosen
- Move images following the date they have been taken
- Names with numbers of different sizes
- Add a value to numbers
- Change the case (upper-case/lower-case)
- Replace the '.' (dots) with ' ' (spaces)
- Extract only the end of a string
- Extract only the beginning of a string
- Invert elements, delete some
- Array extraction with elements separated with strings
- The "The" problem
- Delete the beginning of a string until a given character
- Delete a "delimited" substring
- Regular expressions
- Rename associated files
- Rename associated files while renumbering them
- Rename with Roman numerals
- Default examples

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

- From :
  `IMG_3975.JPG` taken the `09/09/2003` at `21h47m58s`
- To :
  `Planet_Mars_20030909_214758.jpg`
- Use the expression :
  `Planet_Mars_%Xdo.jpg`

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`

#### Append a date following the format you've chosen

Let's take the file `"Note.txt"` modified the 01/02/2003

- From : `Note.txt`
- To : `Note-01-02-03.txt`
- Use the expression : `%b-%dm{"%m-%d-%y"}.%e`

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

#### Move images following the date they have been taken

- Under Windows :
  - From :
    `IMG_3975.JPG` taken the `09/09/2003`
    `IMG_3981.JPG` taken the `10/10/2005`
  - To :
    `C:\Photo\2003\09\09\IMG_3975.jpg
    C:\Photo\2005\10\10\IMG_3981.jpg`
  - Use the expression :
    `C:\\Photo\\%Xdo{"%Y\\%m\\%d"}\\%b.%le`
- Under GNU/Linux :
  - From :
    `IMG_3975.JPG` taken the `09/09/2003`
    `IMG_3981.JPG` taken the `10/10/2005`
  - To :
    `/home/user/Photo/2003/09/09/IMG_3975.jpg
    /home/user/Photo/2005/10/10/IMG_3981.jpg`
  - Use the expression :
    `/home/user/Photo/%Xdo{"%Y/%m/%d"}/%b.%le`

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

- Under Windows : `

  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

  `
- Under GNU/Linux : `

  /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

#### Names with numbers of different sizes

- From :
  `Img1.jpg
  Img2.jpg
  Img10.jpg`
- To :
  `Img_001.jpg
  Img_002.jpg
  Img_010.jpg`
- Use the expression :
  `Img_%N.%e or Img_%N{3}.%e`

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"

> `

#### Add a value to numbers

- From :
  `Img50.jpg
  Img125.jpg
  Img180.jpg`
- To :
  `Img55.jpg
  Img130.jpg
  Img185.jpg`
- Use the expression :
  `Img%N{1,5}.%e`

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"

> `

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

- From : `SONG TITLE.MP3`
- To : `Song title.mp3`
- Use the expression : `%Lf`

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

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

- From : `My.preferred.movie.avi`
- To : `My preferred movie.avi`
- Use the expression : `%b("."," ").%e`

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

#### Extract only the end of a string

- From :
  `A0B1C2DE_0201.jpg
  A1B#0302.gif`
- To :
  `0201.jpg
  0302.gif`
- Use the expression :
  `%f(-8)`

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

- `%b(2,1) gives "B"` : positive start, so relative to the beginning
- `%b(-2,1) gives "E"` : negative start, so relative to the end

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

#### Extract only the beginning of a string

- From :
  `A0B1C2DE_0201.jpg
  A1B#0302.gif`
- To :
  `A0B1C2DE.jpg
  A1B.gif`
- Use the expression :
  `%b(1,-5).%e`

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 :

- `"A0B1C2DE_0201"` so 13 characters
- `"A1B#0302"` so 8 characters

`%b(1,-5)` will be equivalent to :

- on `"A0B1C2DE_0201"` : 13 - 5 so 8 characters starting at position 1 so `"A0B1C2DE"`
- on `"A1B#0302"` : 8 - 5 so 3 characters starting at position 1 so `"A1B"`

`%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

#### Invert parts, delete some

- From :
  `Song Title 1 - Singer - Site.mp3
  Title 2 - Singer.mp3`
- To :
  `Singer - Song Title 1.mp3
  Singer - Title 2.mp3`
- Use the expression :
  `%b[2] - %b[1].%e`

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

#### Array extraction with elements separated with strings

- From : `Artist =##= Album =##= Song.mp3`
- To : `Song.mp3`
- Use the expression : `%b("=##=","-")[3].mp3`

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

#### 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'.

- From :
  `The Beatles - Eleanor Rigby.mp3`
- To :
  `Beatles, The - Eleanor Rigby.mp3`
- Use the expression :
  `%b[1](5), The - %b[2].%e`

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

#### Delete the beginning of a string until a given character

- From :
  `Good - Singer - Title 1.mp3
  Excellent - Singer - Title 2 - Site.mp3`
- To :
  `Singer - Title 1.mp3
  Singer - Title 2 - Site.mp3`
- Use the expression :
  `%f[2,0,"-"]`

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

#### Delete a "delimited" substring

- From :
  `Title 1 (www.site.net) Singer 1.mp3
  Title 2(192 (44100) 3m30s)Singer 2.mp3`
- To :
  `Title 1 - Singer 1.mp3
  Title 2 - Singer 2.mp3`
- Use the expression :
  `%f[1,"("] - %f[-1,")"]`

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

#### Regular expressions

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

- Separate words with spaces
  - From : `APhotoOfAGarden.jpg`
  - To : `A Photo Of A Garden.jpg`
  - Use the expression :
    `%b(s/(.)([A-Z])/\1 \2/g)(s/([A-Z])([A-Z])/\1 \2/g).%e`
- Prefix with 'B' if the file has been modified in the first half of an hour, 'A' otherwise
  - From : `File.txt` modified at 16h12m
  - To : `B - File.txt`
  - Use the expression :
    `%dmt{"%M"}(s/[012]./B/)(s/../A/) - %f`

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.

- From :
  `1.srt
  Z2.srt
  F8.srt`
- To :
  `Fi1-A.srt
  Fi2-B.srt
  Fi3-C.srt`
- Use the expression :
  `%<2,1>b.%e`

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`

- 2 : indicates that each group is made of two files
- 1 : indicates that the following variable will be extracted from the first member of each group.
  Based on the selection made this means extracted from the `"avi"`.
- b : indicates the base name of the file

`%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

#### Rename associated files while renumbering them

- From :
  `IMG_3975.JPG
  IMG_3975.RAW
  PIC10222.JPG
  PIC10222.RAW`
- To :
  `Img_001.JPG
  Img_001.RAW
  Img_002.JPG
  Img_002.RAW`
- Use the expression :
  `%e-Img_%nc.%e;%f[2]`

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

#### 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.

- From :
  `PHOTO.jpg
  VIDEO.avi
  MUSIC.mp3
  DOCUMENT.odt`
- To :
  `PHOTO - I.jpg
  VIDEO - II.avi
  MUSIC - III.mp3
  DOCUMENT - IV.odt`
- Use the expression :
  `%b - %T{"C:\\romnum.txt"}.%e`

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

#### 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.