Picard strips off leading zero from track numbers

I have every track in my whole library formatted with leading zero in the track number in the ID3v.2.3
01, 02, 03 … 09,10,11,12,… This is necessary in order to make external software sort things correctly.
If that is not done properly, you will get a sort order like 1,10,11,12… and so on.
But when I use Picard to tag files, it strips these leading zeroes off.
Is there a way to prevent Picard from doing that?

You can use the $num() function.
In the file naming script: $num(%tracknumber%,2)
In the tags, try: $set(tracknumber,$num(%tracknumber%,2)) in Advanced > Scripting
I’m not sure about the last one, I don’t use it personally.


Just out of interest what software is this? It is rather stupid to sort something that is by definition numerical not numerically :slight_smile:

But try as @mfmeulenbelt wrote above. I hope this works, but it could be that the tagging library we use strips those leading zeros.


@mfmeulenbelt, thanks for your advice. However, I do not know where (how) to script in Picard. Can you point me to some documentation on how scripting is done in Picard?

Just do as mfmeulenbelt wrote: Open Options > Advanced > Scripting and add the following line into the text area there:


In Picard’s options, under Advanced > Scripting you have to tick the box and paste the code in the field underneath it. The script should work after you reload a release. The documentation on Picard scripting is here, though it forgets to mention where to put all those functions. Perhaps that information could be added? Or can it be found somewhere else?

1 Like

Excellent guys!
You’ve been most helpful. Thank you so much :slight_smile:

If you only want to have a leading zero in the tracknumber if the total number of tracks is 10 or bigger, then you could use this enhanced line:


This way you will get tracknumbers like 1/9, 2/9, 3/9…9/9 and 01/10, 02/10, 03/10, 10/10