# Switch numbers and words in filename

**URL:** <https://community.mp3tag.de/t/switch-numbers-and-words-in-filename/49469>\
**Category:** Support\
**Created:** [June 28, 2020, 7:51pm UTC](https://community.mp3tag.de/t/switch-numbers-and-words-in-filename/49469 "2020-06-28T19:51:58Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![ciltocruz](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ciltocruz/32/7832_2.png) [@ciltocruz](https://community.mp3tag.de/u/ciltocruz)\
**Post date:** [June 28, 2020, 7:51pm UTC](https://community.mp3tag.de/t/switch-numbers-and-words-in-filename/49469/1 "2020-06-28T19:51:58Z")

</div>

Hello:

I do not know where to place this topic but I have spent hours looking for information and I have not achieved my goal.

I have these files with the following title:

Posh DJ podcast - DJ Christian Torres 12319.mp3  
Posh DJ podcast - DJ BeatBreaker 122518.mp3

My intention is to achieve this:  
DJ Christian Torres - Posh DJ podcast - Episode 12-3-19.mp3  
DJ BeatBreaker - Posh DJ podcast - Episode 25-12-18.mp3

The changes are:

- Switch the first 2 groups of words
- Add "Episode" before the date
- Change the date format: the original is monthdayyear and my objetive is day-month-year. Here is a complex problem because the date may not have 6 digits. But it is known that the year is always 2 digits at the end.

Can you give me a hand to solve this? I've been "playing" with actions groups and regex replacements but haven't gotten much done...

Thank you very much.

---

<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 29, 2020, 4:50am UTC](https://community.mp3tag.de/t/switch-numbers-and-words-in-filename/49469/2 "2020-06-29T04:50:22Z")

</div>

What do your tags look like?  
If the information is only available in the unstructured string of the filename then import the data first into the structured tags with Convert\>Filename-Tag:  
Format string: %artist% - %title%

Then create an action of the type "Format value" for EPISODE (a user-defined field that you have to type in)  
Format string: `$regexp(%title%,.*(\d+),$1)`  
This fills the field EPISODE with the number. YOu can see the field EPISODE in the extended tags dialogue (Alt-T).  
Now remove the number from title with an action of the type "Replace with regular expression" for TITLE  
Search string: `(.*) \d+`  
Replace with: $1

Now, to format the numbers ... I would treat every case separately - and by "case" I mean the length of the EPISODE.  
So filter for  
$len(%episode%) IS 4  
then create an action of the type "Replace with regular expression" for EPISODE:  
Search string: `(\d)(\d)(\d\d)`  
Replace string: $1-$2-$3  
Do more or less the same for EPISODE with the 5 digits:  
$len(%episode%) IS 5  
Search string: `(\d\d)(\d)(\d\d)`  
Replace string: $1-$2-$3  
and finally  
Search string: `(\d\d)(\d\d)(\d\d)`  
Replace string: $1-$2-$3

Now you can rename the files with  
Convert\>Tag-Filename  
Format string: %title% - %artist% - Episode %episode%

---

<div class="post-metadata">

**Author:** ![Crissov](https://community.mp3tag.de/user_avatar/community.mp3tag.de/crissov/32/6619_2.png) [@Crissov](https://community.mp3tag.de/u/Crissov)\
**Post date:** [June 29, 2020, 5:01am UTC](https://community.mp3tag.de/t/switch-numbers-and-words-in-filename/49469/3 "2020-06-29T05:01:45Z")

</div>

How do you know that `12319` is from January 23 and not December 3? (You only ruled out 12 March.)

---

<div class="post-metadata">

**Author:** ![ciltocruz](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ciltocruz/32/7832_2.png) [@ciltocruz](https://community.mp3tag.de/u/ciltocruz)\
**Post date:** [June 29, 2020, 12:43pm UTC](https://community.mp3tag.de/t/switch-numbers-and-words-in-filename/49469/4 "2020-06-29T12:43:13Z")

</div>

@Crissov  
Sorry, I was wrong about the date. You are right, it is March 12.

I think I will change the date part manually.  
Current files do not have a "point" of separation. (I did "replace" a long time ago)  
In the new files, this point is obtained.

![image](https://community.mp3tag.de/uploads/default/original/2X/1/1223a20340b443f41b5c1d728ede711457931cd1.png)

---

<div class="post-metadata">

**Author:** ![ciltocruz](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ciltocruz/32/7832_2.png) [@ciltocruz](https://community.mp3tag.de/u/ciltocruz)\
**Post date:** [June 29, 2020, 12:47pm UTC](https://community.mp3tag.de/t/switch-numbers-and-words-in-filename/49469/5 "2020-06-29T12:47:54Z")

</div>

@ohrenkino  
I am going to try this solution this afternoon.

I bring a new way to achieve my goal:

I have these files with the following title:

Posh DJ podcast - DJ Christian Torres 12319.mp3  
Posh DJ podcast - DJ BeatBreaker 122518.mp3

The tags? Currently they do not exist.  
My intention is to achieve this:  
%titlename% = "DJ Christian Torres - Posh DJ podcast - Episode 12-3-19.mp3"

%filename% =%title% (without extension)  
%artist% = DJ Christian Torres  
%album% = Posh DJ podcast  
%albumartist% = Posh DJ podcast  
%year% = 2019 -\> I understand that this can be very complicated. I could do it manually if I can't add this tag.

* * *

%titlename% = "DJ BeatBreaker - Posh DJ podcast - Episode 25-12-18.mp3"

%filename% =%title% (without extension)  
%artist% = DJ BeatBreaker  
%album% = Posh DJ podcast  
%albumartist% = Posh DJ podcast  
%year% = 2018 -\> I understand that this can be very complicated. I could do it manually if I can't add this tag.

* * *

The first thing I want to do is change the name of the file to generate the labels from it.

I don't know if it is possible, from the current name, to create the labels and then rename the file based on the labels.

As a colophon, it would be great to set the track number according to the playback date. But this I understand that it is also very complicated.

Thanks a lot.

---

<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 29, 2020, 12:54pm UTC](https://community.mp3tag.de/t/switch-numbers-and-words-in-filename/49469/6 "2020-06-29T12:54:15Z")

</div>

> [@ciltocruz](#):
>
> %titlename% = "DJ Christian Torres - Posh DJ podcast - Episode 12-3-19.mp3"  
> %filename% =%title% (without extension)

I think you mixed them both up.  
The file property by which you find a file in the file system is the %\_filename%.  
The embedded metadata field is called %title% and usually has no extension.

> [@ciltocruz](#):
>
> %year% = 2018 -\> I understand that this can be very complicated. I could do it manually if I can't add this tag.

If you know that the last 2 digits are always the year, then you could extract those from the filename with an action of the type "Format value" for YEAR  
Format string: `20$regexp(%_filename%,'.*(\d\d)$',$1)`

---

<div class="post-metadata">

**Author:** ![ciltocruz](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ciltocruz/32/7832_2.png) [@ciltocruz](https://community.mp3tag.de/u/ciltocruz)\
**Post date:** [June 29, 2020, 1:51pm UTC](https://community.mp3tag.de/t/switch-numbers-and-words-in-filename/49469/7 "2020-06-29T13:51:27Z")

</div>

> [@ohrenkino](#):
>
> > [@ciltocruz](#):
> >
> > %titlename% = "DJ Christian Torres - Posh DJ podcast - Episode 12-3-19.mp3"  
> > %filename% =%title% (without extension)
> 
> I think you mixed them both up.  
> The file property by which you find a file in the file system is the %\_filename%.  
> The embedded metadata field ist called %title% and usually has no extension.

My apologies.

I have confused the term but not what I want to do with each one.

(Sorry about the way to call the tags, I am still not familiar with MP3-TAG syntax, so I put the tag between "%")

%titlename% = "DJ Christian Torres - Posh DJ podcast - Episode 12-3-19.mp3"

%title% =%filename% (without extension)

> [@ohrenkino](#):
>
> > [@ciltocruz](#):
> >
> > %year% = 2018 -\> I understand that this can be very complicated. I could do it manually if I can't add this tag.
> 
> If you know that the las 2 digits are always the year, then you could extract those form the filename with an action of the type "Format value" for YEAR  
> Format string: `20$regexp(%_filename%,'.*(\d\d)$',$1)`

I am going to try this later.

Thanks a lot @ohrenkino

---

<div class="post-metadata">

**Author:** ![ciltocruz](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ciltocruz/32/7832_2.png) [@ciltocruz](https://community.mp3tag.de/u/ciltocruz)\
**Post date:** [June 29, 2020, 5:59pm UTC](https://community.mp3tag.de/t/switch-numbers-and-words-in-filename/49469/8 "2020-06-29T17:59:39Z")

</div>

> [@ohrenkino](#):
>
> If the information is only available in the unstructured string of the filename then import the data first into the structured tags with Convert\>Filename-Tag:  
> Format string: %artist% - %title%
> 
> Then create an action of the type "Format value" for EPISODE (a user-defined field that you have to type in)  
> Format string: `$regexp(%title%,.*(\d+),$1)`  
> This fills the field EPISODE with the number. YOu can see the field EPISODE in the extended tags dialogue (Alt-T).  
> Now remove the number from title with an action of the type "Replace with regular expression" for TITLE  
> Search string: `(.*) \d+`  
> Replace with: $1
> 
> Now, to format the numbers ... I would treat every case separately - and by "case" I mean the length of the EPISODE.  
> So filter for  
> $len(%episode%) IS 4  
> then create an action of the type "Replace with regular expression" for EPISODE:  
> Search string: `(\d)(\d)(\d\d)`  
> Replace string: $1-$2-$3  
> Do more or less the same for EPISODE with the 5 digits:  
> $len(%episode%) IS 5  
> Search string: `(\d\d)(\d)(\d\d)`  
> Replace string: $1-$2-$3  
> and finally  
> Search string: `(\d\d)(\d\d)(\d\d)`  
> Replace string: $1-$2-$3
> 
> Now you can rename the files with  
> Convert\>Tag-Filename  
> Format string: %title% - %rtist% - Episode %episode%

Hello!!

It has not worked but almost.  
There must be a small misprint that I am unable to find. I have tried at [http://regexr.com/](http://regexr.com/) and it should work but I haven't got it on MP3Tag.

First step: OK

Second step: Create label ---\> FAULT. I have only been able to extract the last digit.

Step Three: Can I do something automatic to find out the length of the episode? I have searched in the actions and there is no automatic filter. Do I have to use the filter section in Mp3Tag to filter from the whole list of elements?

Step Four: Final File Rename: OK (supposedly it should work if the episode had been successfully  
extracted)

Regards!

---

<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 29, 2020, 6:06pm UTC](https://community.mp3tag.de/t/switch-numbers-and-words-in-filename/49469/9 "2020-06-29T18:06:11Z")

</div>

> [@ciltocruz](#):
>
> There must be a small misprint that I am unable to find. I have tried at [http://regexr.com/](http://regexr.com/) and it should work but I haven't got it on MP3Tag.

Do not use an external checker but use Convert\>Tag-Tag in MP3tag to test the expression.  
Show me what you do as step 2.

---

<div class="post-metadata">

**Author:** ![ciltocruz](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ciltocruz/32/7832_2.png) [@ciltocruz](https://community.mp3tag.de/u/ciltocruz)\
**Post date:** [June 29, 2020, 11:16pm UTC](https://community.mp3tag.de/t/switch-numbers-and-words-in-filename/49469/10 "2020-06-29T23:16:29Z")

</div>

First Step:

![image](https://community.mp3tag.de/uploads/default/original/2X/3/363709ae421197e8e38e004cf53b3f10b385fd61.png)

Second Step:

![image](https://community.mp3tag.de/uploads/default/original/2X/9/90e1a5736589f9f6f749546978b12bb7ee534c93.png)

This is the result:

![image](https://community.mp3tag.de/uploads/default/original/2X/4/425ba5f8fb43455e43d4444250336dae6d583339.png)

Regards!

---

<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 30, 2020, 4:34am UTC](https://community.mp3tag.de/t/switch-numbers-and-words-in-filename/49469/11 "2020-06-30T04:34:59Z")

</div>

The regular expression is missing a blank:  
`$regexp(%title%,.* (\d+),$1)`

---

<div class="post-metadata">

**Author:** ![ciltocruz](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ciltocruz/32/7832_2.png) [@ciltocruz](https://community.mp3tag.de/u/ciltocruz)\
**Post date:** [June 30, 2020, 10:37pm UTC](https://community.mp3tag.de/t/switch-numbers-and-words-in-filename/49469/12 "2020-06-30T22:37:15Z")

</div>

You are a genious.

Everything has worked perfectly.  
I'm going to save these steps as a group action.

I have more casuistry in my audio files that I hope I can tag correctly with MP3tag.

Thank you from the heart for the help provided.

---

<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:** [July 30, 2020, 10:37pm UTC](https://community.mp3tag.de/t/switch-numbers-and-words-in-filename/49469/13 "2020-07-30T22:37:18Z")

</div>

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