# Is there a way to format the file name by discnumber?

**URL:** https://community.mp3tag.de/t/is-there-a-way-to-format-the-file-name-by-discnumber/64059
**Category:** Support
**Created:** [March 13, 2024, 12:53pm UTC](https://community.mp3tag.de/t/is-there-a-way-to-format-the-file-name-by-discnumber/64059 "2024-03-13T12:53:42Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![scdhh](https://community.mp3tag.de/user_avatar/community.mp3tag.de/scdhh/32/16434_2.png) [@scdhh](https://community.mp3tag.de/u/scdhh)
#### Post date: [March 13, 2024, 12:53pm UTC](https://community.mp3tag.de/t/is-there-a-way-to-format-the-file-name-by-discnumber/64059/1 "2024-03-13T12:53:42Z")

</div>

Here is a piece of pseudo-code(I think that should help with understanding?)

```auto
discs = set()

for i in songs:
    cd.add(i.discnumber)

if len(discs)<=1:
    formatter='$num(%track%,2) - %title%'
else:
    formatter=r'Disc %discnumber%\$num(%track%,2) - %title%'

for i in songs:
    i.save(formatter)

```

Anyway, I want to realize  
If the selected songs all have the same discnumber (or no discnumber)  
Then use `$num(%track%,2) - %title%` formatting  
If from more than one discnumber  
then use `Disc %discnumber%\$num(%track%,2) - %title%` formatting

Is it possible to implement this logic inside mp3tag?  
Or is there any api that would allow me to implement this in an external program?

---

<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: [March 13, 2024, 1:03pm UTC](https://community.mp3tag.de/t/is-there-a-way-to-format-the-file-name-by-discnumber/64059/2 "2024-03-13T13:03:45Z")

</div>

> [@scdhh](#):
>
> `%discnumber%\$num(%track%,2) - %title%` formatting

You could try:  
`[%discnumber%\]$num(%track%,2) - %title%`  
which works for files that either have a discnumber - and for those the discnumber should be included in the path - or don't. And for those the discnumber should not be used for the path.

---

<div class="post-metadata">

### Author: ![scdhh](https://community.mp3tag.de/user_avatar/community.mp3tag.de/scdhh/32/16434_2.png) [@scdhh](https://community.mp3tag.de/u/scdhh)
#### Post date: [March 13, 2024, 1:16pm UTC](https://community.mp3tag.de/t/is-there-a-way-to-format-the-file-name-by-discnumber/64059/3 "2024-03-13T13:16:57Z")

</div>

It's perfect for files that don't have a discnumber.  
But some albums mark all files with discnumber 1  
Maybe I can clear it out manually 🤔

---

<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: [March 13, 2024, 1:24pm UTC](https://community.mp3tag.de/t/is-there-a-way-to-format-the-file-name-by-discnumber/64059/4 "2024-03-13T13:24:03Z")

</div>

What does the discnumber look like for the ones with discnumber 1?  
You could filter for these, e.g.:  
NOT %discnumber% is "1/1"

---

<div class="post-metadata">

### Author: ![scdhh](https://community.mp3tag.de/user_avatar/community.mp3tag.de/scdhh/32/16434_2.png) [@scdhh](https://community.mp3tag.de/u/scdhh)
#### Post date: [March 13, 2024, 1:33pm UTC](https://community.mp3tag.de/t/is-there-a-way-to-format-the-file-name-by-discnumber/64059/5 "2024-03-13T13:33:10Z")

</div>

There should be have 1/1.  
I've also seen 01, or just 1.

 ![image](https://community.mp3tag.de/uploads/default/original/3X/c/8/c8b7bbe699645d5af1f699be4699b26891c8b362.png)

---

<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: [March 13, 2024, 1:36pm UTC](https://community.mp3tag.de/t/is-there-a-way-to-format-the-file-name-by-discnumber/64059/6 "2024-03-13T13:36:49Z")

</div>

does a simple "1" mean that there are no further discs? Or is the first of a set of discs?  
If you know which formats should be excluded, then you can use all these in the filter expression.

> **[Filter and Search – Mp3tag Documentation](https://docs.mp3tag.de/filter/)**
>
> Documentation on Filter and Search and keywords to form complex filter expressions. Mp3tag is the universal Tag Editor.

fitlers can be appended with AND or OR.

---

<div class="post-metadata">

### Author: ![MotleyG](https://community.mp3tag.de/user_avatar/community.mp3tag.de/motleyg/32/440_2.png) [@MotleyG](https://community.mp3tag.de/u/MotleyG)
#### Post date: [March 14, 2024, 12:47am UTC](https://community.mp3tag.de/t/is-there-a-way-to-format-the-file-name-by-discnumber/64059/7 "2024-03-14T00:47:55Z")

</div>

> [@scdhh](#):
>
> If the selected songs all have the same discnumber (or no discnumber)  
> Then use `$num(%track%,2) - %title%` formatting  
> If from more than one discnumber  
> then use `Disc %discnumber%\$num(%track%,2) - %title%` formatting

This is the string I use that applies Disc-Track if there is more than one disc in a set. It also works whether or not the disc is something like 2 or 2/2. It also shortens each field to a max length of 80 characters to stay within the limits of some older OS.  
`..\Music\$left(%albumartistsort%,80)\$left(%albumsort%,80)\$ifgreater(%totaldiscs%,1,$left(%discnumber%,1)-,)$num(%track%,2) $left(%titlesort%,80)`

---

<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: [April 13, 2024, 12:48am UTC](https://community.mp3tag.de/t/is-there-a-way-to-format-the-file-name-by-discnumber/64059/8 "2024-04-13T00:48:38Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
