# Help with conditional format of filename from tag field

**URL:** <https://community.mp3tag.de/t/help-with-conditional-format-of-filename-from-tag-field/14890>\
**Category:** Support\
**Created:** [July 7, 2013, 8:40pm UTC](https://community.mp3tag.de/t/help-with-conditional-format-of-filename-from-tag-field/14890 "2013-07-07T20:40:40Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sven\_Golly](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/s/3bc359/32.png) [@Sven\_Golly](https://community.mp3tag.de/u/Sven_Golly)\
**Post date:** [July 7, 2013, 8:40pm UTC](https://community.mp3tag.de/t/help-with-conditional-format-of-filename-from-tag-field/14890/1 "2013-07-07T20:40:40Z")

</div>

I admit, regex's give me a headache even though I try now and then. Anyway, I read through most of the posts and can't really find any analog to what I want to do. Basically, I want to reformat the filename of a song from Tags as follows:

%artist% - %title% - %disknumber%

BUT, I only want the "- %disknumber%" to appear if %disknumber% is not empty. If %disknumber% is empty the filename should display as:

My Artist - Song Title

with no trailing " - "

But if disknumber contains something like SC001 then it should appear as:

My Artist - Song Title - MyDiskNumber

Hope that's clear. Thanks for the help!

---

<div class="post-metadata">

**Author:** ![dano](https://community.mp3tag.de/user_avatar/community.mp3tag.de/dano/32/6_2.png) [@dano](https://community.mp3tag.de/u/dano)\
**Post date:** [July 7, 2013, 8:45pm UTC](https://community.mp3tag.de/t/help-with-conditional-format-of-filename-from-tag-field/14890/2 "2013-07-07T20:45:20Z")

</div>

The official discnumber tag is with a **c**

Anyway, does this do what you want?  
%artist% - %title%[- %disknumber%]

---

<div class="post-metadata">

**Author:** ![Sven\_Golly](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/s/3bc359/32.png) [@Sven\_Golly](https://community.mp3tag.de/u/Sven_Golly)\
**Post date:** [July 7, 2013, 9:15pm UTC](https://community.mp3tag.de/t/help-with-conditional-format-of-filename-from-tag-field/14890/3 "2013-07-07T21:15:49Z")

</div>

Actually, yes it does. I found that feature buried in the HELP not more than 1/2 hour after I posted my question.

---

<div class="post-metadata">

**Author:** ![Sven\_Golly](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/s/3bc359/32.png) [@Sven\_Golly](https://community.mp3tag.de/u/Sven_Golly)\
**Post date:** [July 8, 2013, 12:11am UTC](https://community.mp3tag.de/t/help-with-conditional-format-of-filename-from-tag-field/14890/4 "2013-07-08T00:11:53Z")

</div>

OK but now I'm puzzled. I'd like to have this sort of thing be an Action that I can apply it quickly rather than go through the Tag -\> Filename convert thing and then pull it the history from the dropdown.

So I've tried both the Format Action using \_FILENAME as the source and that string as the Format AND I've tried the REPLACE Action.

Both give me the same result on testing. 1 of 1 tag formatted, 0 of 1 files renamed. What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![dano](https://community.mp3tag.de/user_avatar/community.mp3tag.de/dano/32/6_2.png) [@dano](https://community.mp3tag.de/u/dano)\
**Post date:** [July 8, 2013, 4:27am UTC](https://community.mp3tag.de/t/help-with-conditional-format-of-filename-from-tag-field/14890/5 "2013-07-08T04:27:09Z")

</div>

It should work with a Format value action.

_Action type:_ **Format value**  
_Field:_ **\_FILENAME**   
_Format string:_ **%artist% - %title%[- %disknumber%]**

Maybe the file had already the right file name?

---

<div class="post-metadata">

**Author:** ![NoToneS](https://community.mp3tag.de/user_avatar/community.mp3tag.de/notones/32/307_2.png) [@NoToneS](https://community.mp3tag.de/u/NoToneS)\
**Post date:** [August 21, 2013, 9:34am UTC](https://community.mp3tag.de/t/help-with-conditional-format-of-filename-from-tag-field/14890/6 "2013-08-21T09:34:54Z")

</div>

> [@Sven Golly](#):
>
> %artist% - %title% - %disknumber%

Try adding this to [Tag \> Filename]

[-ARTIST/Disk/Album/Track/Title/Albumartist -]$replace($replace($replace($replace($replace($left($if((%artist%%albumartist%),$if($eql(%artist%,%albumartist%),$replace(%albumartist%,-,$char(8211)) - ,$if(%artist%,$replace(%artist%,-,$char(8211)) - ,$if(%albumartist%,.$replace(%albumartist%,-,$char(8211)) - ,))),\<!Unknown! - \>)[- Artist -][- Disk -]$if(%discnumber%,D$num(%discnumber%,) - ,)[- Disk -][- Album -]$if(%album%,$replace(%album%,-,$char(8211)) - ,)[- Album -][- Track -]$if(%track%,$num(%track%,2) - ,)[Track][- Title -]$if((%artist%%albumartist%),$if($eql(%artist%,%albumartist%),$if(%title%,$replace(%title%,-,$char(8211)),notitle),[----]$if(%artist%,$if(%albumartist%,$if(%title%,$replace(%title%,-,$char(8211)),notitle) $char(8226) %albumartist%,$if(%title%,$replace(%title%,-,$char(8211)),notitle)),$if(%title%,$replace(%title%,-,$char(8211)),notitle))[----]),$if(%title%,$replace(%title%,-,$char(8211)),notitle))[- Title -],179),/,;),\*,$char(164)),&,&),:,; ),",'''')

i could shorten above and remove [some stuff between these] to trim it down but i'm to lazy once i had what i wanted i left it alone.

---

<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:24pm UTC](https://community.mp3tag.de/t/help-with-conditional-format-of-filename-from-tag-field/14890/7 "2026-02-09T12:24:35Z")

</div>

Closed on February 9, 2026, 12:24pm UTC


