# create a filename with optional portions

**URL:** https://community.mp3tag.de/t/create-a-filename-with-optional-portions/13246
**Category:** Support
**Created:** [March 21, 2012, 2:03pm UTC](https://community.mp3tag.de/t/create-a-filename-with-optional-portions/13246 "2012-03-21T14:03:18Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![prorokrak](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/p/e47c2d/32.png) [@prorokrak](https://community.mp3tag.de/u/prorokrak)
#### Post date: [March 21, 2012, 2:03pm UTC](https://community.mp3tag.de/t/create-a-filename-with-optional-portions/13246/1 "2012-03-21T14:03:18Z")

</div>

Hi, I would like to rename my files according to this scheme:

- If there is not track number, I want my filename like this: Artist - Title
- If there is track number then the name should follow this schme: (track) Artist - Title

I tried to use this action, but it doesn't work. What am I doing wrong?  
$validate($if($isdigit(%track%),'('$num(%track%)') ',2),)%artist% - %title%,\_)

---

<div class="post-metadata">

### Author: ![ohrenkino](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ohrenkino/32/4843_2.png) [@ohrenkino](https://community.mp3tag.de/u/ohrenkino)
#### Post date: [March 21, 2012, 4:51pm UTC](https://community.mp3tag.de/t/create-a-filename-with-optional-portions/13246/2 "2012-03-21T16:51:03Z")

</div>

> [@Prorok Rak](#):
>
> If there is not track number...

You could use the converter Tag-Filename and the mask  
[(%track%)]%artist% - %title%  
The square brackets enclose the optional part

---

<div class="post-metadata">

### Author: ![prorokrak](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/p/e47c2d/32.png) [@prorokrak](https://community.mp3tag.de/u/prorokrak)
#### Post date: [March 21, 2012, 5:00pm UTC](https://community.mp3tag.de/t/create-a-filename-with-optional-portions/13246/3 "2012-03-21T17:00:31Z")

</div>

Unbelievable. Who would say it's so easy.  
Thank you.

---

<div class="post-metadata">

### Author: ![pone](https://community.mp3tag.de/user_avatar/community.mp3tag.de/pone/32/272_2.png) [@pone](https://community.mp3tag.de/u/pone)
#### Post date: [March 21, 2012, 5:11pm UTC](https://community.mp3tag.de/t/create-a-filename-with-optional-portions/13246/4 "2012-03-21T17:11:17Z")

</div>

If it is crucial for your naming filenames, that %track% has to be a number, this is the optional %track% part like you wanted it in the first way:

$if($isdigit(%track%),'('$num(%track%,2)')' ,)

---

<div class="post-metadata">

### Author: ![ra7h35m20s](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/r/779978/32.png) [@ra7h35m20s](https://community.mp3tag.de/u/ra7h35m20s)
#### Post date: [April 25, 2012, 8:33pm UTC](https://community.mp3tag.de/t/create-a-filename-with-optional-portions/13246/5 "2012-04-25T20:33:25Z")

</div>

Not sure how much detail you want in your filenames but this is how I like my filenames....

If I have multi disc sets then I append the discnumber as in the format below. Inversely, no multi disc just %track% %title%

%discnumber%-%track% %title%

For example:

The Album "Days of Rising Doom" from AINA. Disc 2, Track 2 would look like this:

2-17 The Beast Within

(I also number all tracks sequentially from 1 - number of tracks ... this seems to make it easier for some apps in the sorting process I have found)

I suppose the mechanics of it may be a bit confusing. But if you have the field %totaldiscs% or an equivalent this will work in your action group ...

**Action:**** Format Value**

1. Field: \_FILENAME
2. Format String: $ifgreater(%totaldiscs%,1,$left(%discnumber%,2)-$num(%track%,2) %title%,$num(%track%,2) %title%)

Hope this helps you....

---

<div class="post-metadata">

### Author: ![DetlevD](https://community.mp3tag.de/user_avatar/community.mp3tag.de/detlevd/32/123_2.png) [@DetlevD](https://community.mp3tag.de/u/DetlevD)
#### Post date: [April 26, 2012, 2:15am UTC](https://community.mp3tag.de/t/create-a-filename-with-optional-portions/13246/6 "2012-04-26T02:15:33Z")

</div>

> [@Prorok Rak](#):
>
> Hi, I would like to rename my files according to this scheme:
> 
> - If there is not track number, I want my filename like this: Artist - Title
> - If there is track number then the name should follow this schme: (track) Artist - Title

Try this format string expression with an action of your choice ...

**$if(%TRACK%,'('$num(%TRACK%,2)') ',%DUMMY%)%ARTIST%' - '%TITLE%)**

If you want to prepend the running disc number, then try this expression ...

**$ifgreater(%TOTALDISCS%,1,$num(%DISCNUMBER%,1)'-',%DUMMY%)$if(%TRACK%,'('$num(%TRACK%,2)') ',%DUMMY%)%ARTIST%' - '%TITLE%)**

DD.20120436.0636.CEST

---

<div class="post-metadata">

### Author: ![prorokrak](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/p/e47c2d/32.png) [@prorokrak](https://community.mp3tag.de/u/prorokrak)
#### Post date: [April 26, 2012, 4:50pm UTC](https://community.mp3tag.de/t/create-a-filename-with-optional-portions/13246/7 "2012-04-26T16:50:57Z")

</div>

Thank you all for your tips.

---

<div class="post-metadata">

### Author: ![system](https://community.mp3tag.de/uploads/default/original/2X/c/ce7035d426cb755a7916793326d23b465222a407.png) [@system](https://community.mp3tag.de/u/system)
#### Post date: [February 9, 2026, 12:23pm UTC](https://community.mp3tag.de/t/create-a-filename-with-optional-portions/13246/8 "2026-02-09T12:23:44Z")

</div>


