
Rename templates can contain IfExpression tokens to specify complex expressions specified immediately after the token.
The syntax of an expression is as follows:
expression slice {and or or expression slice}...
Using and and or constructs, multiple tests can be performed with a single IfExpression token. There is no precedence difference between and and or. The slices are evaluated strictly left to right.
Each expression slice is defined as one of the following forms:
{qualifiers}... item1 text operator {qualifiers} item2
{qualifiers}... item1 numeric operator item2
{qualifiers}... item1 boolean operator
Items
Items can be field references, property references, strings or integer values.
Field references are the name of a field (built in or custom) enclosed in [ ] brackets. Leading and trailing spaces inside the brackets are ignored as is alphabetic case. Typically item1 in an expression will be a field reference. Note that fields can be track variables. Examples:
[Artist] represents the contents of the Artist field.
[track] represents the contents of the Track field.
In the unlikely case that you have a custom field whose name contains a ] character, it can be escaped as ]]. For example a custom field named Abc [#] would be specified as [Abc [#]]].
Property references are the name of a property bracketed by ! ! characters. Leading and trailing spaces inside the ! ! sequence are ignored as is alphabetic case. Examples:
!File Count! represents the number of selected files.
!Has Chapters! will be 1 if the audio file contains chapters, otherwise 0.
Strings can be any text enclosed in double quote characters. If the text contains a double quote character specify it as "". Examples:
"simple text"
"Clarence ""Gatemouth""" Brown"
Integer examples:
5
-1
Note: All fields, properties, track variables, qualifiers and operators can be inserted from the token editor's context menu via the IfExpression Support submenu.
Qualifiers
Qualifiers are case insensitive and can be the following:
Note that qualifiers are reset at the start of each expression slice.
Operators
There are three types of operators: text, numeric and boolean. The following holds:
The following operators are available:
| Operator Type | Operator | Description |
|---|---|---|
| Text | equals | True if the the two items are equal. |
| Text | contains | True if item1 contains the text in item2. |
| Text | starts with | True if item1 starts with the text in item2. |
| Text | ends with | True if item1 ends with the text in item2. |
| Numeric | == | True if item1 has the same integer value as item2. |
| Numeric | != | True if item1 does not have the same integer value as item2. |
| Numeric | < | True if item1 is numerically less than item2. |
| Numeric | <= | True if item1 is numerically less than or equal to item2. |
| Numeric | > | True if item1 is numerically greater than item 2. |
| Numeric | >= | True if item1 is numerically greater than or equal to item2. |
| Boolean | is true | true if item1 has a non zero integer value or is true. A not qualifier is valid between is and true. |
| Boolean | is false | true if item1 has a zero integer value. A not qualifier is valid between is and false. |
IfExpression token expressions immediately follow the token and continue until the next token is encountered. If on true, the first item you want to include is text, you must follow the expression text with a Break token.
Example 1:
❨Initial Filename❩ ❨IfExpression❩ [Comments] contains "test note" ❨Break❩ - ❨Comments❩ ❨endIf❩
The expression is true if the Comments field (default) contains the case insensitive text test note. When true, the Comments field is appended to the filename.
Example 2:
❨Initial Filename❩ ❨IfExpression❩ [Comments] contains case sensitive "test note" ❨Break❩ - ❨Comments❩ ❨endIf❩
The expression is true if the Comments field (default) contains the case sensitive text test note. The expression could have been constructed as the following for the same effect:
case sensitive [Comments] contains "test note" ❨Break❩ - ❨Comments❩
Example 3:
❨Initial Filename❩ - ❨IfExpression❩ not [Artist] starts with "the" and [Artist] ends with " band" ❨Break❩The ❨Artist❩ ❨Else❩ ❨Remove Leading Articles❩❨Artist❩❨Preserve Leading Articles❩ ❨endIf❩
The expression is true if the Artist field does not start with the and ends with space band. When true the word The inserted at the start of the inserted Artist field. When false, leading articles are removed before the Artist field is included.
Example 4:
❨IfExpression❩ [Disc] == 0 ❨Break❩01 ❨Else❩ ❨Disc Pad2❩ ❨endIf❩ .❨Track Pad2❩❨Title❩
The template is used to rename tracks to dd.tt title. The IfExpression token is used to change disc numbers of 0 to 1.
Example 5:
❨Folder Start❩ ❨Album❩ ❨IfExpression❩ [genre] any equals "classical" ❨Break❩ - (classical) ❨endIf❩
The template is used to rename containing folders to the Album field. If any item in the Genre field is Classical, - (classical) is appended to the folder name. In a rather constructed case, this would work if the Genre field was Folk;;;Classical.
Example 6:
❨Title❩ ❨IfExpression❩ !Has Chapters! is true ❨Break❩ - [chapters] ❨endIf❩
The template is used to rename tracks to the Title field. If the file has chapters, - [chapters] is appended.