Discnumber Action

I want to populate the Discnumber tag from a string in the directory name.


If directory = 'Greatest Hits' then Discnumber = 01
If directory = 'Greatest Hits CD1' then Discnumber = 01
If directory = 'Greatest Hits CD2' then Discnumber = 02
If directory = 'Greatest Hits CD3' then Discnumber = 03


I think I need to use an Action, probably Format Value but I'm not sure what to enter in the Format String field.

Please can anyone help?



Did you do a search for "discnumber" here in the forum?
If so, you should get many results, which can help you to learn how to solve your problem.

Especially this thread seems to be a good starting point:
Generating %DISCNUMBER% Tags


Yes, I did search the forums but with little understanding of the scripting functions I could not get a neat solution.

I will endeavour to crack the the $if and $regexp functions and post if a get a result.



I have the answer

(please note this will only work where the directory name contains CDn where n = 1 thru 9)


Please let me know if there are errors with this.

Right, this looks good to me.
You can make it a little bit more 'safe' by respecting the space character in the $strstr() functions.
$ifgreater($strstr(%_directory%,' CD'),0,$num($mid(%_directory%,$add($strstr(%_directory%,' CD'),3),1),2),01)

Try to understand how $regexp() works. A regular expressions e. g. can find a string fragment at end of the string, or e. g. can isolate only numbers at end of a string, and can help to solve so much more other problems you can think of.

$num($if($eql($regexp(%_directory%,'^.* CD(\d*)$','$1'),%_directory%),1,$regexp(%_directory%,'^.* CD(\d*)$','$1')),2)


ok iam wondering if Mp3tag has a better way to write discnunber tag automatically yet based on folder name CD1 CD2 CD3 so you end up with 1/3 2/3 3/3

and yes i have searched looking for the answer for 2 days now with no joy

a lot of the stuff i found is over ten years old iam hoping things are better now

There is no function to detect and number discs.
You have to create your own actions or simply set the value by hand or import the data from the folder (if it can be found there).
When you look at your data: what criteria does it supply to find out with which disc one would be dealing at the moment?

will this is the best so far as an action
format value DISCNUMBER$ifgreater($strstr(%_directory%,'CD'),0,$num($mid(%_directory%,$add($strstr(%_directory%,'CD'),2),1),2),01)

and i get DISCNUMBER 01 02 03
02 03
better would be DISCNUMBER 1 2 3
best would be DISCNUMBER 1/3 2/3 3/3

An action of the type "Guess value" may be shorter:
Source: %_directory%
Format string: %dummy%CD%discnumber%
then add another action to the action group:

Format value for DISCNUMBER
Format string: $num(%discnumber%,1)
this should remove all leading zeros.


Format string: $num(%discnumber%,1)
should work

ok cool that worked now get

discnumber 1 2 3

that all do for now

can we get discnumber 1/3 2/3 3/3 yet ?

Only manually.
Or with an action of the type "Format value" where you have to set the total manually.
Or with the function Convert>Tag-Tag
In both cases use
Format string: %discnumber%/3
(and replace "3" with the correct total number)
The Convert function may be easier to use than to edit the action.

an action where you have to set the total manually. would be fine

i will see if my music program likes discnumber 1 2 3

You could create a set of action, each for a different total - I think the totals of 2, 3 and 4 would be used most frequently.

can we not tell mp3tag to count the number of folders ?

Show me how.
MP3tag only looks at the current file and does not know anything about previous or coming files (and their folders).
As repeated a number of times: there is (currently) no special function for discnumbers.

ok can we have an input box to ender a string in an action ? enter total number of disks say 11 disks then mp3tag would know set discnumber as 1/11 2/11 3/11 and so on

This feature is currently not available.
Here is a thread from 2007 about this topic:

An action is called for every file. So if there were such a feature you would have to enter that data umpteen times, once for each file.
I think the Convert>Tag-Tag function is much better in this case.