# Generating %DISCNUMBER% Tags

**URL:** https://community.mp3tag.de/t/generating-discnumber-tags/4117
**Category:** Support
**Created:** [November 28, 2006, 2:05pm UTC](https://community.mp3tag.de/t/generating-discnumber-tags/4117 "2006-11-28T14:05:05Z")
**Posts on this page:** 9
**Page:** 3

<div class="post-metadata">

### Author: ![pone](https://community.mp3tag.de/user_avatar/community.mp3tag.de/pone/32/272_2.png) [@pone](https://community.mp3tag.de/u/pone)
#### Post date: [April 22, 2014, 4:01pm UTC](https://community.mp3tag.de/t/generating-discnumber-tags/4117/41 "2014-04-22T16:01:00Z")

</div>

**$regexp(%\_directory%,.+(\d).\*,$1)**

That's what I'm using. It's simple but effective. It gives you the last number (single digit) of the directory name. That works almost for all sorts of folder naming schemes.

---

<div class="post-metadata">

### Author: ![Logan](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/278dde/32.png) [@Logan](https://community.mp3tag.de/u/Logan)
#### Post date: [April 22, 2014, 4:33pm UTC](https://community.mp3tag.de/t/generating-discnumber-tags/4117/42 "2014-04-22T16:33:03Z")

</div>

Wow- nothing like bring an eight year old thread back!

---

<div class="post-metadata">

### Author: ![chrisp\_uk](https://community.mp3tag.de/user_avatar/community.mp3tag.de/chrisp_uk/32/7761_2.png) [@chrisp\_uk](https://community.mp3tag.de/u/chrisp_uk)
#### Post date: [April 22, 2014, 7:19pm UTC](https://community.mp3tag.de/t/generating-discnumber-tags/4117/43 "2014-04-22T19:19:38Z")

</div>

> [@DetlevD](#):
>
> **$if($neql($regexp(%\_directory%,'^.\*\s\*(?:Disc|CD)\s\*0\*(\d+).\*$','$1',0),%\_directory%),$regexp(%\_directory%,'^.\*\s\*(?:Disc|CD)\s\*0\*(\d+).\*$','$1',0),%DISCNUMBER%)**
> 
> DD.20140422.1255.CEST

Thank you, that works nicely. It is so elegant once you know but it just didn't occur to me 🙂

---

<div class="post-metadata">

### Author: ![woelfchen](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/w/d9b06d/32.png) [@woelfchen](https://community.mp3tag.de/u/woelfchen)
#### Post date: [July 5, 2014, 5:09am UTC](https://community.mp3tag.de/t/generating-discnumber-tags/4117/44 "2014-07-05T05:09:53Z")

</div>

> [@pone](#):
>
> **$regexp(%\_directory%,.+(\d).\*,$1)**  
> That's what I'm using. It's simple but effective. It gives you the last number (single digit) of the directory name. That works almost for all sorts of folder naming schemes.

this one with the condition, when the foldername contains "cd[number]", "CD[number]", "disc[number]" or "DISC[number]":

**$if($and($isdigit($regexp(%\_directory%,.+(\d)._,$1)),$or($grtr($strstr($lower(%\_directory%),'cd'),0), $grtr($strstr($lower(%\_directory%),'disc'),0))),$regexp(%\_directory%,.+(\d)._,$1),)**

---

<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: [July 5, 2014, 8:22am UTC](https://community.mp3tag.de/t/generating-discnumber-tags/4117/45 "2014-07-05T08:22:44Z")

</div>

> [@woelfchen](#):
>
> ... with the condition, when the foldername contains "cd[number]", "CD[number]", "disc[number]" or "DISC[number]":  
> **$if($and($isdigit($regexp(%\_directory%,.+(\d)._,$1)),$or($grtr($strstr($lower(%\_directory%),'cd'),0), $grtr($strstr($lower(%\_directory%),'disc'),0))),$regexp(%\_directory%,.+(\d)._,$1),)**

Returns this expression the same result?

**$regexp(%\_directory%,'.\*(?:cd|disc|disk)\s\*0\*(\d+).\*','$1',1)**

resp.

**$if($neql($regexp(%\_directory%,'.\*(?:cd|disc|disk)\s\*0\*(\d+).\*','$1',1),%\_directory%),$regexp(%\_directory%,'.\*(?:cd|disc|disk)\s\*0\*(\d+).\*','$1',1),)**

... or ...

**$if($eql($regexp(%\_directory%,'.\*(?:cd|disc|disk)\s\*0\*(\d+).\*',,1),),$regexp(%\_directory%,'.\*(?:cd|disc|disk)\s\*0\*(\d+).\*','$1',1),)**

DD.20140705.1230.CEST  
Edit. Suppress leading zeroes.  
DD.20140705.1852.CEST

---

<div class="post-metadata">

### Author: ![woelfchen](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/w/d9b06d/32.png) [@woelfchen](https://community.mp3tag.de/u/woelfchen)
#### Post date: [July 5, 2014, 11:52am UTC](https://community.mp3tag.de/t/generating-discnumber-tags/4117/46 "2014-07-05T11:52:30Z")

</div>

> [@DetlevD](#):
>
> Returns this expression the same result?
> 
> **$regexp(%\_directory%,'.\*(?:cd|disc)\s\*(\d+).\*','$1',1)**
> 
> resp.
> 
> **$if($neql($regexp(%\_directory%,'.\*(?:cd|disc)\s\*(\d+).\*','$1',1),%\_directory%),$regexp(%\_directory%,'.\*(?:cd|disc)\s\*(\d+).\*','$1',1),)**
> 
> DD.20140705.1230.CEST

nearly...

these are my test-folders:  
a cd01 (test)  
b disc02 (test)  
cd 03 (test)  
d disc 04 (test)  
e keine disc

the first expression also creates 'eine' for the last folder, rest in two-digits (with a leading zero)  
the second expression works nearly correct (no discnumber for the last folder), but the rest in two-digits (with a leading zero)

---

<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: [July 5, 2014, 3:00pm UTC](https://community.mp3tag.de/t/generating-discnumber-tags/4117/47 "2014-07-05T15:00:05Z")

</div>

> [@woelfchen](#):
>
> nearly... two-digits (with a leading zero) ...

I have changed my formatstring in order to suppress leading zeroes, ...  
now both formatstrings give nearly the same result.  
Note: Prepare your formatstring also for discnumbers greater than 9.

Here is an export script with test cases ...  
[Test.20140705.ExtractCDNumber.mte](https://community.mp3tag.de/uploads/default/original/2X/3/3dd58b3caf75e467139ef368b8350f65b057f88b.mte) (5.76 KB)

DD.20140705.1900.CEST

[Test.20140705.ExtractCDNumber.mte](https://community.mp3tag.de/uploads/default/original/2X/3/3dd58b3caf75e467139ef368b8350f65b057f88b.mte) (5.76 KB)

---

<div class="post-metadata">

### Author: ![woelfchen](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/w/d9b06d/32.png) [@woelfchen](https://community.mp3tag.de/u/woelfchen)
#### Post date: [July 5, 2014, 8:13pm UTC](https://community.mp3tag.de/t/generating-discnumber-tags/4117/48 "2014-07-05T20:13:41Z")

</div>

> [@DetlevD](#):
>
> I have changed my formatstring in order to suppress leading zeroes

thx, now i've two alternatives 😉

---

<div class="post-metadata">

### Author: ![system](https://community.mp3tag.de/uploads/default/original/2X/c/ce7035d426cb755a7916793326d23b465222a407.png) [@system](https://community.mp3tag.de/u/system)
#### Post date: [February 9, 2026, 12:20pm UTC](https://community.mp3tag.de/t/generating-discnumber-tags/4117/49 "2026-02-09T12:20:01Z")

</div>



[Previous page](https://community.mp3tag.de/t/generating-discnumber-tags/4117.md?page=2)
