Single Action for Auto Renumbering Tracks with a Leading Zero

Hello Everyone :slight_smile:

So far, I have alternately applied the Auto-numbering Wizard and a Filename-to-Tag format string to renumber tracks to display a leading zero, for eg. 01, 02, 099. Now, skipping any one of these two methods, and using only the Filename Field:

If any number, and sample, of tracks, which almost invariably preceded by a track number in some format, are to be auto-renumbered to display the required leading zero in the Track Field, how will this be achieved through a single action? Is it possible to derive at a solution at all, in spite of the many different ways in which the track numbers are usually integrated with the Filename? To name but a few examples:

1 File Name

  1. File Name
    1 - File Name
    01 File Name
  2. File Name
    01 - File Name
    99 File Name
    100 - File Name

Thank you for your assistance.

Note: It is not required to format the TRACK field having any leading zero!
If I remember right, the file type MP4 does not like any leading zero digit at all within the TRACK tagfield.

Here is a formatstring, which get the leftmost number from the filename.
The result should be stored into the tagfield TRACK.

TRACK <== $regexp(%_filename%,'^0*(\d+)[\.\s\-]+(.+?)$','$1') From: 1 File Name 1. File Name 1 - File Name 01 File Name 01. File Name 01 - File Name 99 File Name 100 - File Name To: 1 1 1 1 1 1 99 100


Thank you very much for taking the time to provide the solution, DetlevD. The leading zero is simply my own preference. :smiley:

I created an Action using the regular expression you provided, but it did not deliver any result. I conclude that I misunderstood you on how to apply it. These were my steps:

ACTIONS > New (Renumber Tracks with Leading Zero) > Regular Expression Field: TRACK > Regular Expression: $regexp(%_filename%,'^0*(\d+)[.\s-]+(.+?)$','$1').

The type of action should be "Format value" - the regular expression is already in the $regexp() function. So what you did, was more or less apply a regular expression twice the second one being an invalid expression though.

So try "Format value" for TRACK

Thank you, Ohrenkino, I missed that.

Quickly re-tried it, but the tracks were numbered without the zero.

I want to point out, that my formatstring proposal does not "Renumber Tracks with Leading Zero".
Read again the given example.

Once you have isolated the track number from the filename, and stored this track number within the tagfield TRACK, you can create a new filename of your wish.
While doing this, you may store leading zeroes into the new filename as you like it.

Using the converter "Tag - Tag" [Alt+5], you can get a preview how a formatstring works.
Field: TEST
... or ...
Field: TRACK
Formatstring: $regexp(%_filename%,'^0*(\d+)[.\s-]+(.+?)$','$1')

If the formatstring works ok and delivers the track number only, then put this formatstring as an action "Format value on tagfield TRACK" into an actiongroup with a name of your wish.

Once you have the isolated track number stored within the tagfield TRACK, then you may create a new filename.
As usual you may do zero-padding the track number.

_FILENAME <== $num(%TRACK%,3)'. '%TITLE%' - '%ARTIST%


Thank you DetlevD. I am unable to pay the attention due to it, straight away. I will do so by Sunday or Monday, and will report if I run into problems again.

Have a great weekend all. :slight_smile:

DetlevD, my English is not good enough to thoroughly grasp what you are are explaining. It think I also failed to explain properly what I needed, to begin with. Could try again, please? Here goes:

I want to renumber the tracks to contain a leading zero- wherever the zero is appropriate. Each track should be numbered according to, but irrespective of, the number format of the current track number which is contained in each file name. Once this action is completed, and the new track numbers now contain the required leading zero, I will proceed to rename the file names where needed.

In conjunction with the above, I wish to combine another action with which to renumber the tracks of multi-disc albums, but is probably advisable to post that as a separate topic.

I am always very grateful for any assistance.

If you want to re-format an existing entry in TRACK to get more leading zeros, try an action of the type
Format value for TRACK
Format string: $num(%track%,2)

Thank you, but I see a problem arising when a zeroes have to be added--or not added--to a large number of differently formatted TRACK fields, simultaneously. Some TRACK fields may already have the leading zero, some not, and then some tracks may not even be numbered at all. That is one reason for wishing to use the filename to supply the track number. The other is to ensure that the track number and the title in the filename, always corresponds i.e. that there is not a mismatch of title and track number.

If you want to remove leading zeroes from the track number you may apply the following formatstring against the tagfield TRACK:
Converter "Tag-Tag" ... or ... Action "Format value".
Field: TRACK
Formatstring: $if(%TRACK%,$num(%TRACK%,1),)



DetlevD, but I want to add -- not subtract -- the zero to the track number in the Field: TRACK, by using the filename as the source. I am disheartened by my lack of ability to explain this any better, and I hope that it will not discourage you, or anyone else, from proposing a solution.

Ohrenkino's solution is already good to go, bar one little problem:


To me, his solution appears to be less complicated, because it neutralizes my requirement for the original filename to be used as source for the track number. I have yet to test it extensively, and the only shortcoming I have found so far is that it will not correctly apply the track number when the Field: TRACK is blank, in which case all the track numbers are converted to "00".

If you want to follow the proposal from above post #2, then you will get the track number from the given filename written into the tagfield TRACK.
As a following step you may adjust the TRACK value with leading zero numbers by using function $num(), but keep in mind that there is at least one file format (MP4) in the world, which cannot store such track number format with leading zero.
If there are already track numbers in the tagfield TRACK, then you can step over getting track number from filename.

The function $num() can help to format the tag-field TRACK as you like it.
Within this thread you got already examples for all cases how to apply the function $num():
$num(%TRACK%,1) ... remove leading zeroes, gives just the number;
$num(%TRACK%,2) ... prepend the zero character to give two digit number strings: 00,01,02,03,04,05,06,07,08,09;
$num(%TRACK%,3) ... prepend the zero character to give three digit number strings: 000,001,002,...,010,011,012.

As you have pointed out, the filenames need a consistent format.
Once you have already formatted track numbers in the tagfield TRACK, then you can apply the given content from the tagfield TRACK to built a proper filename, by using the content operator %TRACK%.

Keep in mind that the tagfield TRACK does not need to be formatted with leading zeroes, because all formatting can be done within a format string 'on the fly' by applying the function $num() on the content operator %TRACK% (see above).

You got already the hint for a fitting formatstring, e. g.: $if(%TRACK%,$num(%TRACK%,2),)


Thank you DetlevD, I will concentrate and try again. You have been very patient, and helpful.