# Padding numerical value in Title or Filename

**URL:** https://community.mp3tag.de/t/padding-numerical-value-in-title-or-filename/15117
**Category:** General Discussion
**Created:** [October 19, 2013, 4:04pm UTC](https://community.mp3tag.de/t/padding-numerical-value-in-title-or-filename/15117 "2013-10-19T16:04:28Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![DavidJ](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/d/d2c977/32.png) [@DavidJ](https://community.mp3tag.de/u/DavidJ)
#### Post date: [October 19, 2013, 4:04pm UTC](https://community.mp3tag.de/t/padding-numerical-value-in-title-or-filename/15117/1 "2013-10-19T16:04:28Z")

</div>

So far I've been able to accomplish many changes with MP3Tag, what a great tool! But the last thing I'm having difficulty with is the track # in either the title or filename.

When the CD's were ripped, the track field was padded with a preceeding "0" like this; 01/21, 02/21, etc... The Title however, lists track 01 as Chapter 1, so when the list of tracks are played, Chapter 1 is played, then Chapter 11, then 12, etc... then 2, then 21, etc...

So I'm trying to figure out how to rename only the tracks with a filename (or title) ending with a 1 - 9, so that they end with a 01, 02, etc..

I found a thread talking about the function of "Formatstring: $cutLeft(%\_filename%,17)" which at first I thought could modify to do what I needed, but then decided that it really wasn't the solution without a lot of additional work. Other threads didn't give me much hope either.

I could accomplish this manually, but I have about 300 tracks to modify ☹

Any help would be appreciated!

David...

---

<div class="post-metadata">

### Author: ![ohrenkino](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ohrenkino/32/4843_2.png) [@ohrenkino](https://community.mp3tag.de/u/ohrenkino)
#### Post date: [October 19, 2013, 7:19pm UTC](https://community.mp3tag.de/t/padding-numerical-value-in-title-or-filename/15117/2 "2013-10-19T19:19:08Z")

</div>

instead of simply using %track% to write the track number use  
$num(%track%,2)

So in order to get the filename with padded numbers try the converter Tag-Filename and the mask  
%title% - $num(%track%,2)

---

<div class="post-metadata">

### Author: ![DavidJ](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/d/d2c977/32.png) [@DavidJ](https://community.mp3tag.de/u/DavidJ)
#### Post date: [October 19, 2013, 8:01pm UTC](https://community.mp3tag.de/t/padding-numerical-value-in-title-or-filename/15117/3 "2013-10-19T20:01:27Z")

</div>

> [@ohrenkino](#):
>
> instead of simply using %track% to write the track number use  
> $num(%track%,2)
> 
> So in order to get the filename with padded numbers try the converter Tag-Filename and the mask  
> %title% - $num(%track%,2)

Thanks ohrenkino,

That's close, by using that mask the filename changes from "Chapter 1.flac" to - "Chapter 1 - 01.flac".

What I'd like to have is just Chapter 01.flac. Is that possible?

---

<div class="post-metadata">

### Author: ![poster](https://community.mp3tag.de/user_avatar/community.mp3tag.de/poster/32/4881_2.png) [@poster](https://community.mp3tag.de/u/poster)
#### Post date: [October 20, 2013, 3:44am UTC](https://community.mp3tag.de/t/padding-numerical-value-in-title-or-filename/15117/4 "2013-10-20T03:44:50Z")

</div>

> [@DavidJ](#):
>
> What I'd like to have is just Chapter 01.flac. Is that possible?

Instead of trying to change the filename you should build it complete new with "covert Tag-Filename".  
That naturally only works, if your filename ist build of filled tags.

---

<div class="post-metadata">

### Author: ![DetlevD](https://community.mp3tag.de/user_avatar/community.mp3tag.de/detlevd/32/123_2.png) [@DetlevD](https://community.mp3tag.de/u/DetlevD)
#### Post date: [October 20, 2013, 6:28am UTC](https://community.mp3tag.de/t/padding-numerical-value-in-title-or-filename/15117/5 "2013-10-20T06:28:39Z")

</div>

> [@DavidJ](#):
>
> ... I'm having difficulty with is the track # in either the title or filename. ... So I'm trying to figure out how to rename only the tracks with a filename (or title) ending with a 1 - 9, so that they end with a 01, 02, etc.. ...  
> Any help would be appreciated! David...

If you don't want to fully re/create the filename from the values of the tag fields by a fitting format string, then you may use the converter "Tag - Filename" with one format string from the following proposals ...

**$trimRight(%\_filename%,'0123456789 -\_.()#''') $regexp(%\_filename%,'[\d\s\-\_.()#'''']+$',%DUMMY%)**

These format strings may remove more characters from the right edge of the filename as you want it, but I am sure, that you are able to adapt the examples to your need.

Afterwards you can concatenate the track number formatted as you wish, e. g. with a format string like ...

**%\_filename%' '$num(%TRACK%,2)**

In the event that a track number does not exist, then you may apply this format string ...

**$trimRight(%\_filename%,'0123456789')$num(%\_counter%,2)**

... or ...

**$trimRight(%\_filename%,' 0123456789')' '$num(%\_counter%,2)**

DD.20131020.1058.CEST

---

<div class="post-metadata">

### Author: ![DavidJ](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/d/d2c977/32.png) [@DavidJ](https://community.mp3tag.de/u/DavidJ)
#### Post date: [October 21, 2013, 12:27pm UTC](https://community.mp3tag.de/t/padding-numerical-value-in-title-or-filename/15117/6 "2013-10-21T12:27:51Z")

</div>

Thanks DetlevD, that's exactly what I needed!

I had no idea MP3Tag was so powerful, it reminds me of when I was struggling with formulas in Excel...

I ended up combining both statements and was able to batch process large quantities of files at once.  
$trimRight(%_filename%,'0123456789 -_.()#''')' '$num(%TRACK%,2)

Thanks again!!  
David
