Add discnumber with separator only when Discnumber exists

I have run into small issue, I want to use filename formatting as:

%discnumber%-$num(%track%,2) - %artist% - %title%

It works well untill I have MultiDisc compilation, but if DiscNumber filed is empyt (Single Disc),
then it only adds separator. How to avoid that?

Basically what I would want to accomplish, would be that separator - after %discnumber% gets only added when Discnumber field actually has something in it. :rolleyes:

[%discnumber%-]$num(%track%,2) - %artist% - %title%

The string between square brackets is only returned if at least one %tag% inside is not empty.

Thank you, that works great... :w00t:

Wonder why I couldnt figure this myself.

Another quick question is, how to mach it backwards?
For example Filenames to Tags if some of those have Discnumber in front of track number others dont?

Sample Case would be:

1-10 - Artist - Title
10 - Artist - Title

As I really wouldnt like to add Discnumer 1 to everyhting...

(Read EDIT at the bottom)

I've just gone through fixing up my format string for tagging and had a similar issue to yourself - I want the %discnumber% field to populate only if there is a %discnumber%


  • if there is only one disc I have the %discnumber% field blank instead of 1 or 1/1 (so I don't need to exclude 1 or 1/1 tags in my format string)
  • I fill %discnumber% as 1/2, 2/2, etc. BUT for the filename I only want it to come out as 1, 2, etc. (ie. truncated to a single digit - this would become an issue for albums covering more than 9 discs, but I only have one album that has 10 discs anyway, so I treat that by itself)
  • this is put together with a two digit track number, resulting in: 01, 02, 03, etc. for single disc albums OR 101, 102, 201, 202, etc. for multiple disc albums.

Here is my current format string:

$if(%albumartist%,%albumartist%,%artist%)\%year% %album%$if(%discnumber%,$num(%discnumber%,1),)$num(%track%,2) %title%

The key point for your self being:


ie. If there is anything in the $discnumber& field, then %discnumber (truncated to one digit) will be added, if the $discnumber% field is blank, then nothing is added.

I quickly put that together with your current code and this should work for you:

$if(%discnumber%,$num(%discnumber%,1)-,)$num(%track%,2) - %artist% - %title%

Keeping in mind that if you don't want a 1- added to single disc album, then $discnumber% must be empty. I'm sure there's a way to code it so 1/1 is also excluded, but I only just figured out the $if commands myself.

Hope this helps (didn't mean for this to become such a long winded reply)

EDIT: I re-read dano's reply and just realised that the square brackets do the same as my $if(x,y,z) method, so may as well use the square brackets. My bad. Either way, if you fill %discnumber% with (1, 2, 3, etc) as opposed to (1/1, 1/2, 2/2) there's no way to distinguish disc 1 out of a multiple disc set from disc 1 out of a single disc album. There would be a way to exclude 1/1 when tagging, but I think it's easier to just make sure single disc albums have an empty %discnumber% field.

EDIT 2: if you wanted to truncate the disc number to one digit using dano's method, use the following:

[$num(%discnumber%,1)-]$num(%track%,2) - %artist% - %title%

Its perfect.

As I always use Single digit Discnumbers or they are just blank. :wink:
I basically truncate all 1/1 format disc & track numbers in My "Standardize" action sequence.

No worries mate, glad I could help - I was looking for the answer to your original question, which then spurred me onto wanting to understand the Boolean functions available. I'd been meaning to redo my my format string for a while and the update will save me a lot of time down the road.

Ahh yes the old "standardise" action sequence, mine is pretty much burnt into my brain by now. Fill albumartist, move feat. from title to artist, autonumber tracks to 01/01 etc., blank out or fix discnumber etc etc etc. Good fun :wink:

Hmm...tested and doesnt Seem to work... <_<

It doesnt match any of tracks, to get tags from filename.
Not even those which actually have single digit discnumber in front.


It seems MellowTone replied to answer your first question, not the second.

Well on the import you cannot use scripting.
You have to do it in two steps with
%discnumber%-%track% - %artist% - %title%
%track% - %artist% - %title%

You can use the Filter to display only files with the discnumber (4 hyphens in the filename):
"$len($regexp(%_filename%,'[^-]',))" IS 4

and for the others
"$len($regexp(%_filename%,'[^-]',))" IS 3

Ok Thats I was afraid I didnt find any solution...

Thx, probably this will be real useful then... :slight_smile:

Actally I came across interesting idea, not sure can it be done, but:

Couldnt I just read "%discnumber%-%track%" combo as %track% and then split it aftrewards by somekind of script which uses tracknumber field and - as separator? :rolleyes:

Or read it as somekind of custom variable and then split it to %discnumber & %track%.
Theoretically it could be possible, as it includes clear separator, which differs from other separators.
"-" VS. " - "

Then it would be possible just create Action group, which includes all the necessary steps.

Anyway...looks like a time to do some experiments on some small group of files... :w00t:

Yes you can do that with a Guess values action.