Feature suggestion: adaptive number padding

Suggestion: adaptive number padding.

Like: $num(%track%,a)

Effect: uses the minimum number of leading 0's for items per subfolder.

Background: As is well known, some software sorts by character (for example: 1.mp3, 10.mp3, 11.mp3, 12.mp3 [...] 19.mp3, 2.mp3, 20.mp3, 21.mp3, etc.) rather than by numerical value (1.mp3, 2.mp3, 3.mp3 [...] 9.mp3, 10.mp3, 11.mp3, 12.mp3, etc.). To fix, this numbers are padded with 0's to force numerically correct sorting, even when sorting by character. (01.mp3, 02.mp3, 03.mp3 [...] 09.mp3, 10.mp3, 11.mp3 [...] 19.mp3, 20.mp3, 21.mp3, etc.)

Current scenario: When one has many files that are grouped in their own subfolders, like albums or books, this may mean that many files have to be processed in order for them to be sorted correctly. In order to speed this up, mp3tag allows us to add as many folders as we like to the work batch and process them all at once with the Convert commands using the $num(%track%,n) flag, allowing us to pad numbers with as many leading zeroes as desired.

If you're fussy, this creates a problem: If there are fewer than 10 files in a folder, the files don't need leading zeroes at all to sort correctly (1.mp3, 2.mp3 [...] 8.mp3, 9.mp3, etc.), if there are more than 9 but fewer than 100 they need only 1 leading zero (01, 02, 03 [...] 09, 10, 11, etc.), more than 99 but fewer than 1000 only need 2 leading zeroes (001, 002, 003 [...] 098, 099, 100, 101, etc.), etc.

If you're like me, you then identify how many files there are in each subfolder so you know how many zeroes to assign, and you process them in batches as outlined above. This requires a lot of digging through folders.

In short: it would be nice if I could just dump entire main folders with many subfolders into mp3tag, run the Convert command $num(%track%,a) and have mp3tag use the minimum number of leading zeroes needed for each subfolder.

This does not belong to this topic. Please start your own topic, and name it accordingly. Be considerate.

THANKS !

The number of files in a folder is probably not the ideal trigger - it is OK for a number of use cases but not for all.
The best way to do it in general would be to supply the total number of grouped files with the help of the track numbering assistant that has a number of possible triggers to reset counters.
Once the number of total tracks has been determined you can use
$num(%track%,$len($regexp(%track%,.*/(\d+),$1)))
to set the number of digits from total tracks which should get the right amount of padding zeros.

In a practical example, how would that work? I am not sure how I would obtain or feed the number of tracks in each subfolder in a large folder into the Convert command. This is beyond my experience.

Did you have a look at the track numbering wizard Ctrl-K and its various options to set and reset the track number.

Thank you for clarifying. I looked at Ctrl+K. I think we may be thinking along different lines. This is what I mean:

Say I have a folder called Books. In it are 25 subfolders for authors. Inside each author folder may be multiple books, each in their own folder, ranging from 6 to 924 tracks per book.

What I would like to be able to do, is to "File\Add directory" the whole Books folder with all of its subfolders and in a single go then rename all files according to the data relevant per individual track and subfolder.

In a single run with 80 subfolders, Convert\ tag > filename \ $num(%track%,a) - %title% would result in renaming files in folders with:

  • less than 10 files, for example: 1 - Credits.mp3, 2 - Chapter 1.mp3 [...] 9 - End credits.mp3
  • more than 9, fewer than 100 files, for example: 01 - Chapter 1.mp3 [...] 78 - Epilogue.mp3
  • more than 99, fewer than 1000 files, for example: 001 - Foreword.mp3 [...] 879 - Discussion.mp3

It is true that files and folders without track data would cause issues in their own subfolder, but that is the same as it is now.

My suggestion is that you use the track numbering assistant before you rename the files.
The assistant uses any folder change (if you set it to do so) and can determine the total number before it resets the track counter.
And after you have assigned the correct track number plus the totals for the grouping criterion you can get the total number from the track number and use that to determine the amount of padding with zeros.

You mean that, in this example, I could add the Books folder with its 80 populated subfolders (and if needed use the track numbering assistant to correct/assign the track data to all the tracks per subfolders in a single go) and then use the expression you provided -- $num(%track%,$len($regexp(%track%,.*/(\d+),$1))) -- to do what I am describing?

Yes.
Set the assistant like that:

Thank you. I will make note of it for future use. I appreciate the explanation and the patience.

Adding an adaptive switch to the $num(%track%) function would introduce undue complexity?

It would break a lot of existing function calls in an awful lot of actions.
But as there is a combination of existing functions I would assume that this is currently the way to go.

Understood. Thanks again.