# Help writing action group to rename file

**URL:** <https://community.mp3tag.de/t/help-writing-action-group-to-rename-file/57498>\
**Category:** Support\
**Created:** [June 3, 2022, 3:16am UTC](https://community.mp3tag.de/t/help-writing-action-group-to-rename-file/57498 "2022-06-03T03:16:06Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Citizen\_Snips](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/c/5daacb/32.png) [@Citizen\_Snips](https://community.mp3tag.de/u/Citizen_Snips)\
**Post date:** [June 3, 2022, 3:16am UTC](https://community.mp3tag.de/t/help-writing-action-group-to-rename-file/57498/1 "2022-06-03T03:16:06Z")

</div>

I have a collection of podcast files with filenames similar to the following:

ADV1104544195.mp3

The numbers after ADV are random but the filename length is fixed, although I don't think this actually matters for what I'm trying to do.

Each file is a podcast episode whose %title% tag is formatted as: "#: Episodename", e.g. one file's %title% tag might be: "12: Foo".

I would like to write an action group that will rename these files using the following format for the above example:

12: Foo (ADV1104544195).mp3

The modified filename needs to include the %title% tag plus the original filename.

The problem I am having is that I cannot figure out a way to store or reference the original filename when specifying the new filename. I thought about storing the original filename in a temporary tag and then reading it back when using the "Format value" command, but mp3tag doesn't seem to allow you to just create and reference new tags, e.g %temp%.

Is there any way to accomplish this?

---

<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:** [June 3, 2022, 5:45am UTC](https://community.mp3tag.de/t/help-writing-action-group-to-rename-file/57498/2 "2022-06-03T05:45:53Z")

</div>

> [@Citizen\_Snips](#):
>
> 12: Foo (ADV1104544195).mp3

This is an invalid filename as it features the colon.

To add something to an exsiting string, use an action of the type "Format value" in this case for \_FILENAME  
Format string: %title% %\_filename%  
You would have to take care that the action is only run once as otherwise you would add the title part each time.

> [@Citizen\_Snips](#):
>
> but mp3tag doesn't seem to allow you to just create and reference new tags, e.g %temp%.

It would be interesting to see how you tried to create the new field. Of course, you can add new fields.

---

<div class="post-metadata">

**Author:** ![Citizen\_Snips](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/c/5daacb/32.png) [@Citizen\_Snips](https://community.mp3tag.de/u/Citizen_Snips)\
**Post date:** [June 3, 2022, 6:50am UTC](https://community.mp3tag.de/t/help-writing-action-group-to-rename-file/57498/3 "2022-06-03T06:50:17Z")

</div>

> [@ohrenkino](#):
>
> To add something to an exsiting string, use an action of the type "Format value" in this case for \_FILENAME  
> Format string: %title% %\_filename%  
> You would have to take care that the action is only run once as otherwise you would add the title part each time.

Thanks, I missed that %\_filename% was one of the fields that could be read by the "Format value" command.

> [@ohrenkino](#):
>
> This is an invalid filename as it features the colon.

Is there any way to have the : be substituted with a - in the new filename, while leaving the : in the %title% field?

> [@ohrenkino](#):
>
> It would be interesting to see how you tried to create the new field.

To create a new tag called %TEMP% and give it the value "foo", I tried this action:

Replace "%TEMP%": "" -\> "foo"

Basically I'm trying to say "replace the empty text in %TEMP% (because the tag doesn't exist yet) with the text "foo"". The action runs, but when I add the "TEMP" tag to the list of visible columns in mp3tag, there is no text listed after running the action. Should I use a regex here instead?

> [@ohrenkino](#):
>
> Of course, you can add new fields.

I didn't think you could because of the text on this page:

> **[Tag Field Mappings – Mp3tag Documentation](https://docs.mp3tag.de/mapping/)**
>
> Overview of all available tag fields, their names in Mp3tag, and how they are mapped to the internal structures of the different tag formats. Mp3tag is the universal Tag Editor.

which says:

> [@](#):
>
> The list below gives an overview of all tag fields available in Mp3tag, their names to be used in Mp3tag, and how they are mapped to the internal structures of the different tag formats.

It seems to suggest only the fields on that page can be manipulated.

---

<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:** [June 3, 2022, 6:55am UTC](https://community.mp3tag.de/t/help-writing-action-group-to-rename-file/57498/4 "2022-06-03T06:55:40Z")

</div>

> [@Citizen\_Snips](#):
>
> Is there any way to have the : be substituted with a - in the new filename, while leaving the : in the %title% field?

yes. try  
Format string `$validate(%title%, -) %_filename%`

> [@Citizen\_Snips](#):
>
> Replace "%TEMP%": "" -\> "foo"

The problem is: there is no reserved space for non-existent fields. So as TEMP did not exist, there were no hits.  
To create a new tag field, use an action of the type "Format value" and enter the new field name without %.

In respect to the page with field names:  
That page tells you which standard fields are supported by MP3tag - and hopefully a lot of players.  
Any field that you create that is not included in that list becomes a user-defined field, a standard-obeying feature which hardly any player supports.

---

<div class="post-metadata">

**Author:** ![Citizen\_Snips](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/c/5daacb/32.png) [@Citizen\_Snips](https://community.mp3tag.de/u/Citizen_Snips)\
**Post date:** [June 3, 2022, 5:03pm UTC](https://community.mp3tag.de/t/help-writing-action-group-to-rename-file/57498/5 "2022-06-03T17:03:14Z")

</div>

> [@ohrenkino](#):
>
> yes. try  
> Format string `$validate(%title%, -) %\_filename%

Thanks, that worked, but what is the purpose of the backtick? I omitted it and the command seems to work fine. Or did you mean to include a closing backtick to format that text as code?

> [@ohrenkino](#):
>
> To create a new tag field, use an action of the type "Format value" and enter the new field name without %.

Thanks, that worked.

---

<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:** [June 3, 2022, 5:06pm UTC](https://community.mp3tag.de/t/help-writing-action-group-to-rename-file/57498/6 "2022-06-03T17:06:17Z")

</div>

> [@Citizen\_Snips](#):
>
> Or did you mean to include a closing backtick to format that text as code?

Yeah, sorry, forgot the closing one - I editted my original post.

---

<div class="post-metadata">

**Author:** ![Citizen\_Snips](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/c/5daacb/32.png) [@Citizen\_Snips](https://community.mp3tag.de/u/Citizen_Snips)\
**Post date:** [June 3, 2022, 5:42pm UTC](https://community.mp3tag.de/t/help-writing-action-group-to-rename-file/57498/7 "2022-06-03T17:42:34Z")

</div>

Thanks, I think I'm starting to get the hang of this now. I have a follow up question:

Suppose I again start with the following file:

`ADV1104544195.mp3`

with title tag: `12: Foo`.

Now suppose I run this file through an mp3 file splitter ([mp3, ogg vorbis and FLAC splitter - mp3splt-project](http://mp3splt.sourceforge.net/mp3splt_page/home.php)) and end up with the following files:

`01_ADV1104544195.mp3`  
`02_ADV1104544195.mp3`  
`03_ADV1104544195.mp3`

Now suppose I would like the final files to look like this:

`01_03_12 - Foo (ADV1104544195).mp3`  
`02_03_12 - Foo (ADV1104544195).mp3`  
`03_03_12 - Foo (ADV1104544195).mp3`

Where the first number in the filename is the track number, the second number is the total number of files, and the third number is the number from the episode number of the %title%.

The easiest way I have found to accomplish this involves using a temporary tag (as explained above) to store the original filename. Here is the sequence of commands I came up with:

`# create a temp tag`  
`Format value "temp_filename": ""`  
`# get the original filename and store it in the temp tag created above; also capture the track number and store it in the track tag`  
`Guess values "%_FILENAME%": %track%_%temp_filename%`  
`# format each split file to include number of tracks, track title, and original filename (stored in the temp tag)`  
`Format value "_FILENAME": $num(%track%,2)_$num(%_total_files%,2)_$validate(%title%, -) (%temp_filename%)`

Is that the easiest way to accomplish what I'm trying to do, or is there a more direct way to do it without using temporary tags as temporary variables?

---

<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:** [June 3, 2022, 5:52pm UTC](https://community.mp3tag.de/t/help-writing-action-group-to-rename-file/57498/8 "2022-06-03T17:52:48Z")

</div>

> [@Citizen\_Snips](#):
>
> `Format value "temp_filename": ""`

This does not work - you cannot create a field with nothing in it.  
You could use Converter\>Tag-Filename with  
Format string: `$num(%track%,2)_$num($mid(%track%,$add($strstr(%track%,/),1)),2)_%title% (%_filename%)`

I don't know what

> [@Citizen\_Snips](#):
>
> `Guess values "%_FILENAME%": %track%_%temp_filename%`

should do in this context esp. as the target string or source string is missing.

---

<div class="post-metadata">

**Author:** ![Citizen\_Snips](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/c/5daacb/32.png) [@Citizen\_Snips](https://community.mp3tag.de/u/Citizen_Snips)\
**Post date:** [June 3, 2022, 9:00pm UTC](https://community.mp3tag.de/t/help-writing-action-group-to-rename-file/57498/9 "2022-06-03T21:00:50Z")

</div>

> [@ohrenkino](#):
>
> This does not work - you cannot create a field with nothing in it.

It does seem to work - it creates the tag "temp\_filename" and populates it with "". It turns out this step is unnecessary though, as the "Guess values" command will automatically create the tag "temp\_filename" and populate it with whatever comes after the first \_ in the filename.

> [@ohrenkino](#):
>
> I don't know what should do in this context esp. as the target string or source string is missing.

It parses the filename to obtain values for %track% and %temp\_filename%; everything before the \_ in the filename is copied to %track% and everything after it is copied to %temp\_filename%. I'm not sure if that is the intended behavior but it does work.

By creating my own tags I now have a way of using variables in this scripting language, which makes many tasks a lot easier.

---

<div class="post-metadata">

**Author:** ![Citizen\_Snips](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/c/5daacb/32.png) [@Citizen\_Snips](https://community.mp3tag.de/u/Citizen_Snips)\
**Post date:** [June 4, 2022, 4:40pm UTC](https://community.mp3tag.de/t/help-writing-action-group-to-rename-file/57498/10 "2022-06-04T16:40:26Z")

</div>

> [@ohrenkino](#):
>
> Format string: `$num(%track%,2)_$num($mid(%track%,$add($strstr(%track%,/),1)),2)_%title% (%_filename%)`

Can you explain how this works? The first part is:

`$strstr(%track%,/)`

Which based on my understanding says "find the first occurrence of / in %track%, but / doesn't appear in track. Does `$strstr` default to the beginning or end of the string if the character isn't found? The documentation page ([Scripting Functions – Mp3tag Documentation](https://docs.mp3tag.de/scripting/)) doesn't specify.

---

<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:** [June 4, 2022, 7:10pm UTC](https://community.mp3tag.de/t/help-writing-action-group-to-rename-file/57498/11 "2022-06-04T19:10:39Z")

</div>

If you have MP3 files like

> [@Citizen\_Snips](#):
>
> `01_03_12 - Foo (ADV1104544195).mp3`  
> `02_03_12 - Foo (ADV1104544195).mp3`  
> `03_03_12 - Foo (ADV1104544195).mp3`

suggests, then the total number of tracks is stored behind the backslash.  
$num() cuts everything off that is not numeric so you have to move the pointer in that string to a character 1 further than the occurrance of the slash.

If you have the field TOTALTRACKS (which would be a user-defined field in MP3 files) then you can use that.

---

<div class="post-metadata">

**Author:** ![Citizen\_Snips](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/c/5daacb/32.png) [@Citizen\_Snips](https://community.mp3tag.de/u/Citizen_Snips)\
**Post date:** [June 4, 2022, 11:05pm UTC](https://community.mp3tag.de/t/help-writing-action-group-to-rename-file/57498/12 "2022-06-04T23:05:03Z")

</div>

> [@ohrenkino](#):
>
> the[n] the total number of tracks is stored behind the backslash.

Is this just the way mp3tag works, or is this some quirk of how Windows works? Why does searching %track% for the first occurrence of / give the total number of tracks?

---

<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:** [June 4, 2022, 11:55pm UTC](https://community.mp3tag.de/t/help-writing-action-group-to-rename-file/57498/13 "2022-06-04T23:55:06Z")

</div>

This is how the standard works for mp3. Both disc and track info has the total shown after a slash.

---

<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:** [June 5, 2022, 4:40am UTC](https://community.mp3tag.de/t/help-writing-action-group-to-rename-file/57498/14 "2022-06-05T04:40:06Z")

</div>

> [@Citizen\_Snips](#):
>
> Why does searching %track% for the first occurrence of / give the total number of tracks?

If that is not the case for your data - how do you know the total number of files?

Here is the definition from the [ID3 standard](https://id3.org/id3v2.3.0):

TRCK  
The 'Track number/Position in set' frame is a numeric string containing the order number of the audio-file on its original recording. This may be extended with a "/" character and a numeric string containing the total numer of tracks/elements on the original recording. E.g. "4/9".

But I see that with

> [@Citizen\_Snips](#):
>
> Guess values "%_FILENAME%": %track%_%temp\_filename%

you overwrite any existing track number with the total files in it so there would probably not be a total.  
In that case the %\_total\_files% variable may be accurate enough, yet, in this case it only represents the number of selected files.

---

<div class="post-metadata">

**Author:** ![Citizen\_Snips](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/c/5daacb/32.png) [@Citizen\_Snips](https://community.mp3tag.de/u/Citizen_Snips)\
**Post date:** [June 5, 2022, 10:16pm UTC](https://community.mp3tag.de/t/help-writing-action-group-to-rename-file/57498/15 "2022-06-05T22:16:46Z")

</div>

Ah, OK, I see what you mean. `$strstr(%track%,/)` assumes `%track%` already includes a `/` and the total number of tracks, e.g. `2/4`. Then `$strstr(%track%,/)` simply returns the position of the `/` and `$mid(%track%,$add($strstr(%track%,/),1))` returns the character that is one after the '/' in `%track%`.

Question: would that line fail if %track% contained two-digit numbers both before and after the slash, e.g. if `%track%` was `02/04`, it seems `$mid(%track%,$add($strstr(%track%,/),1))` would return `0` instead of the intended `4`.

Another question: if `strstr(x,y)` does not find string y in string x, what does it return? As a test, I have the following files (`%track%` for each is a single-digit number, 1, 2, or 3):

`01_ADV1104544195.mp3`  
`02_ADV1104544195.mp3`  
`03_ADV1104544195.mp3`

I ran the following one-liner from above on them:

`Format string: $num(%track%,2)_$num($mid(%track%,$add($strstr(%track%,/),1)),2)_%title (%_filename%)`

And it returned:

`01_01_012 Foo (01_ADV1104544195).mp3`  
`02_02_013 Foo (02_ADV1104544195).mp3`  
`03_03_013 Foo (03_ADV1104544195).mp3`

It looks like because `$strstr(%track%,/)` fails to match `/` in `%track%`, it returns position 0, and `$num($mid(%track%,$add($strstr(%track%,/),1)),2)` just returns the track number expressed as a 2-digit number. Is that correct?

> [@ohrenkino](#):
>
> But I see that with
> 
> > [@Citizen\_Snips](#):
> >
> > Guess values "%_FILENAME%": %track%_%temp\_filename%
> 
> you overwrite any existing track number with the total files in it so there would probably not be a total.  
> In that case the %\_total\_files% variable may be accurate enough, yet, in this case it only represents the number of selected files.

What that is actually doing is reading the track number (not the total number of tracks) and the base filename from `%_FILENAME%` and storing them in `%track%` and `%temp_filename%`, respectively. Each filename is formatted as `#_base_filename`, where `#` is the track number. I use `%_total_files%` to get the total number of files, as you noted.

I suppose this task might be made easier if mp3splt-gtk could just format the `%track%` field to include the total number of tracks to start with. EDIT: apparently mp3splt-gtk does not support "total number of tracks" as one of the fields it can include in the output format, which must explain why I chose this method in the first place.

---

<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:** [June 6, 2022, 7:15am UTC](https://community.mp3tag.de/t/help-writing-action-group-to-rename-file/57498/16 "2022-06-06T07:15:37Z")

</div>

the $strstr stays at position 0 if no match is found.

> [@Citizen\_Snips](#):
>
> `$num($mid(%track%,$add($strstr(%track%,/),1)),2)`

probably the "1" is a little short. Try a 3 or $len(%track%)

Adding the total number of files for a folder is something you can do with the track numbering wizard. Might be a better idea to have the data in the tags and not exclusively in the filename.

---

<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:29pm UTC](https://community.mp3tag.de/t/help-writing-action-group-to-rename-file/57498/17 "2026-02-09T12:29:47Z")

</div>


