# Audiobook file naming from the Series and Series-Part fields ($IF statement)

**URL:** https://community.mp3tag.de/t/audiobook-file-naming-from-the-series-and-series-part-fields-if-statement/63443
**Category:** Support
**Created:** [January 16, 2024, 3:01am UTC](https://community.mp3tag.de/t/audiobook-file-naming-from-the-series-and-series-part-fields-if-statement/63443 "2024-01-16T03:01:47Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![KeithG](https://community.mp3tag.de/user_avatar/community.mp3tag.de/keithg/32/16030_2.png) [@KeithG](https://community.mp3tag.de/u/KeithG)
#### Post date: [January 16, 2024, 3:01am UTC](https://community.mp3tag.de/t/audiobook-file-naming-from-the-series-and-series-part-fields-if-statement/63443/1 "2024-01-16T03:01:47Z")

</div>

Hello everyone!

I am hoping for some help with an Action to rename the audio file.

I'm working with audiobooks, which have the SERIES and SERIES-PART fields (both are TEXT) along with the normal ALBUM, ARTIST, etc fields.

I'd like to format the filename like:

`<ARTIST>\<SERIES>\<SERIES-PART> - <ALBUM> (<YEAR>)\<ARTIST> - (<SERIES> - Book <SERIES-PART>) <ALBUM> (<YEAR>) - <TITLE>`

This produces a folder path like:

```auto
Lois McMaster Bujold\Vorkosigan series\01 - Shards of Honor (1986)\Lois McMaster Bujold - (Vorkosigan series - Book 01) Shards of Honor (1986) - Part 01

```

The issue I'm having is dealing with the `<SERIES-PART>` field.

If `<SERIES-PART>` is less than 10, I'd like to have a leading 0 (zero) added, if not, then use `<SERIES-PART>` as is.

I've tried the following:

`$if($lt($len($num(%Series-Part%,0)),10),%Artist%\%Series%\0%Series-Part% - %Album% (%year%)\%Artist% - (%Series% - Book 0%SERIES-PART%) %Album% (%Year%) - Part $num(%Track%,2),%Artist%\%Series%\%Series-Part% - %Album% (%year%)\%Artist% - (%Series% - Book %SERIES-PART%) %Album% (%Year%) - Part $num(%Track%,2))`

but not matter what, the $IF evaluates as TRUE, and the first condition is always performed. So, if `<SERIES-PART>` is 16, the file is renamed 016 when I'd like only 16 (the FALSE condition).

To throw another wrinkle, working with `<SERIES-PART>` that has a decimal, ie 5.3 or 16.1. I use $NUM(%SERIES-PART%,0) to get everything before the decimal point, as my tests showed $num(16.1,0) returned 16, but no go.

How do I get the $IF to evaluate correctly so that if the `<SERIES-PART>` is less than 10, add a 0,

and

how to deal with `<SERIES-PART>` that have a decimal (again adding a 0 if `<SERIES-PART>` is less than 10 and keeping what is after the decimal)?

Thanks for any help!

---

<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: [January 16, 2024, 7:01am UTC](https://community.mp3tag.de/t/audiobook-file-naming-from-the-series-and-series-part-fields-if-statement/63443/2 "2024-01-16T07:01:12Z")

</div>

Try `$num(%series-part%,2)`instead of the $if-statement.  
Also check the documentation

> **[Scripting Functions – Mp3tag Documentation](https://docs.mp3tag.de/scripting/#boolean-functions)**
>
> Documentation on Mp3tag's scripting functions. Mp3tag is the universal Tag Editor.

if there is a

> [@KeithG](#):
>
> $lt(...

function. I have not found it.

---

<div class="post-metadata">

### Author: ![LyricsLover](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/c6cbf5/32.png) [@LyricsLover](https://community.mp3tag.de/u/LyricsLover)
#### Post date: [January 16, 2024, 7:18am UTC](https://community.mp3tag.de/t/audiobook-file-naming-from-the-series-and-series-part-fields-if-statement/63443/3 "2024-01-16T07:18:30Z")

</div>

`$lt` is a [scripting function](https://picard-docs.musicbrainz.org/en/functions/func_lt.html) from another tagging tool: MusicBrainz Picard.

**Update 14:25:**  
As I just learned, `$lt` seems also to exist in the "Mp3tag for Mac" version:

 ![image](https://community.mp3tag.de/uploads/default/original/3X/3/6/36ebd0d98e9de372b09da3c8dd40842be3ea4455.png)

In the Windows version the same function is called `$less`:

 ![image](https://community.mp3tag.de/uploads/default/original/3X/a/0/a04a52d0bd6e17d52f9bafc6f4ead204192bdc17.png)

---

<div class="post-metadata">

### Author: ![KeithG](https://community.mp3tag.de/user_avatar/community.mp3tag.de/keithg/32/16030_2.png) [@KeithG](https://community.mp3tag.de/u/KeithG)
#### Post date: [January 16, 2024, 12:54pm UTC](https://community.mp3tag.de/t/audiobook-file-naming-from-the-series-and-series-part-fields-if-statement/63443/4 "2024-01-16T12:54:55Z")

</div>

Thanks for the replies!

I found $lt at [https://community.mp3tag.de/t/scripting-functions/51689](https://community.mp3tag.de/t/scripting-functions/51689), but after both of you saying it isn't available I checked [https://docs.mp3tag.de/scripting/](https://docs.mp3tag.de/scripting/) and didn't find it listed. Looking at the community post I see it was in the Mac forum, so maybe it doesn't work in Windows or was removed after that post was made.

I first tried with $num(%series-part%,x) but didn't get it working. I'll go back and try again.

---

<div class="post-metadata">

### Author: ![LyricsLover](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/c6cbf5/32.png) [@LyricsLover](https://community.mp3tag.de/u/LyricsLover)
#### Post date: [January 16, 2024, 1:29pm UTC](https://community.mp3tag.de/t/audiobook-file-naming-from-the-series-and-series-part-fields-if-statement/63443/5 "2024-01-16T13:29:30Z")

</div>

Which Mp3tag version do you use?

The one for Windows (this is the correct support forum for it) or the one for Mac?

---

<div class="post-metadata">

### Author: ![KeithG](https://community.mp3tag.de/user_avatar/community.mp3tag.de/keithg/32/16030_2.png) [@KeithG](https://community.mp3tag.de/u/KeithG)
#### Post date: [January 16, 2024, 1:45pm UTC](https://community.mp3tag.de/t/audiobook-file-naming-from-the-series-and-series-part-fields-if-statement/63443/6 "2024-01-16T13:45:52Z")

</div>

Success!

I was able to get the $IF working by using $LESS for the test condition: $if($less(%series-part%,10)

So my final action is:  
`$if($less(%series-part%,10),%Artist%\%Series%\0%Series-Part% - %Album% (%year%)\%Artist% - (%Series% - Book 0%SERIES-PART%) %Album% (%Year%) - Part $num(%Track%,2)%Artist%\%Series%\0%Series-Part% - %Album% (%year%)\%Artist% - (%Series% - Book 0%SERIES-PART%) %Album% (%Year%) - Part $num(%Track%,2),%Artist%\%Series%\%Series-Part% - %Album% (%year%)\%Artist% - (%Series% - Book %SERIES-PART%) %Album% (%Year%) - Part $num(%Track%,2))`

Thanks LyricsLover! I was writing this reply when you updated your message with the $LESS notation. I'm using the Windows version of MP3Tag, so $LESS is what I needed.

This works for series-part numbers in the format of X(Y).(X)(Y) ie 5, 5.3, 16, 16.1. I have a couple of audiobooks where the series-part is: 5.1-5.3 . In this case I'll have to manually make the changes as "5.1-5.3" is evaluated as bigger than 10.

Have a great day!

---

<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: [January 16, 2024, 2:10pm UTC](https://community.mp3tag.de/t/audiobook-file-naming-from-the-series-and-series-part-fields-if-statement/63443/7 "2024-01-16T14:10:03Z")

</div>

> [@KeithG](#):
>
> So my final action is:  
> `$if($less(%series-part%,10),%Artist%\%Series%\0%Series-Part% - %Album% (%year%)\%Artist% - (%Series% - Book 0%SERIES-PART%) %Album% (%Year%) - Part $num(%Track%,2)%Artist%\%Series%\0%Series-Part% - %Album% (%year%)\%Artist% - (%Series% - Book 0%SERIES-PART%) %Album% (%Year%) - Part $num(%Track%,2),%Artist%\%Series%\%Series-Part% - %Album% (%year%)\%Artist% - (%Series% - Book %SERIES-PART%) %Album% (%Year%) - Part $num(%Track%,2))`

If this is the final code, then I think that it has th part with leading zeros twice.

`$if( $less(%series-part%,10), %Artist%\%Series%\0%Series-Part% - %Album% (%year%)\%Artist% - (%Series% - Book 0%SERIES-PART%) %Album% (%Year%) - Part $num(%Track%,2) %Artist%\%Series%\0%Series-Part% - %Album% (%year%)\%Artist% - (%Series% - Book 0%SERIES-PART%) %Album% (%Year%) - Part $num(%Track%,2) ,%Artist%\%Series%\%Series-Part% - %Album% (%year%)\%Artist% - (%Series% - Book %SERIES-PART%) %Album% (%Year%) - Part $num(%Track%,2))`

Also, I think that the code is rather redudant in respect to parts that are the same for both cases: less than 10 and more than 9.  
I think it could be:  
`%Artist%\%Series%\$if($less(%series-part%,10),0,)%Series-Part% - %Album% (%year%)\%Artist% - (%Series% - Book $if($less(%series-part%,10),0,)%SERIES-PART%) %Album% (%Year%) - Part $num(%Track%,2)`

---

<div class="post-metadata">

### Author: ![KeithG](https://community.mp3tag.de/user_avatar/community.mp3tag.de/keithg/32/16030_2.png) [@KeithG](https://community.mp3tag.de/u/KeithG)
#### Post date: [January 16, 2024, 4:54pm UTC](https://community.mp3tag.de/t/audiobook-file-naming-from-the-series-and-series-part-fields-if-statement/63443/8 "2024-01-16T16:54:40Z")

</div>

Thanks ohrenkino!

I must have copied the parts wrong when I replied. Thanks for catching the error.

Your code is certainly more optimized and overall much easier to read! It hadn't occurred to me to use $IF statements in the body of the code like you did.

---

<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 15, 2024, 4:54pm UTC](https://community.mp3tag.de/t/audiobook-file-naming-from-the-series-and-series-part-fields-if-statement/63443/9 "2024-02-15T16:54:57Z")

</div>

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