# Create filename using $replace

**URL:** https://community.mp3tag.de/t/create-filename-using-replace/49554
**Category:** Support
**Created:** [July 6, 2020, 9:07am UTC](https://community.mp3tag.de/t/create-filename-using-replace/49554 "2020-07-06T09:07:20Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![gsa999](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/g/c6cbf5/32.png) [@gsa999](https://community.mp3tag.de/u/gsa999)
#### Post date: [July 6, 2020, 9:07am UTC](https://community.mp3tag.de/t/create-filename-using-replace/49554/1 "2020-07-06T09:07:20Z")

</div>

Hi  
I'm trying to generate a filename for playlists for each album. The code below works - ie the replacement of the / and : with a - works as does the double quotes with 2 singles, but the code where I am trying to replace 3 dots at the end of an album string with nothing does not work.  
So if the album tag is "For All We Shared..." I want the filename of the playlist to be "For All We Shared.m3u8"

> $filename(%\_folderpath%$replace(%albumartist% - $cutleft(%album%,6),$eql($right(%album%,3),...),,/,-,:, -,",'').m3u8,utf-8)

Any ideas what this code should be please  
Thanks  
G

---

<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: [July 6, 2020, 9:14am UTC](https://community.mp3tag.de/t/create-filename-using-replace/49554/2 "2020-07-06T09:14:38Z")

</div>

you can test expression in Convert\>Tag-Tag.  
Have you tested `$eql($right(%album%,3),...)`?  
The result is a boolean value, no string. You would have to supply the string now - probably in a $if() statement.  
Anyway: why so complicated? Why don't you replace sinply 3 dots with nothing?  
`$replace(%albumartist% - $cutleft(%album%,6),...,,/,-,:, -,",'')`

---

<div class="post-metadata">

### Author: ![gsa999](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/g/c6cbf5/32.png) [@gsa999](https://community.mp3tag.de/u/gsa999)
#### Post date: [July 6, 2020, 9:20am UTC](https://community.mp3tag.de/t/create-filename-using-replace/49554/3 "2020-07-06T09:20:30Z")

</div>

Thanks, I only want to replace the 3 dots with nothing if they appear at the end of the album title, but not anywhere else

---

<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: [July 6, 2020, 9:33am UTC](https://community.mp3tag.de/t/create-filename-using-replace/49554/4 "2020-07-06T09:33:52Z")

</div>

Are you also sure about the $cutleft()  
E.g. and album like "... and then there were three ..."  
would be come  
"d then there were three ..."  
plus the removal of the trailing dots:  
"d then there were three "

To compare strings: `$if($eql(string1,string2),true do this,false do this)`  
`$if($eql($right(%album%,3),...),...,)`

You had a correct syntax in this thread:

> [@Replace characters in filename playlist creation](https://community.mp3tag.de/t/replace-characters-in-filename-playlist-creation/15715):
>
> Hi I'm trying to write an action that trawls through all my mp3s in all folders and creates a playlist in each folder The code below works fine: $filename(%\_folderpath%\$if($eql(%albumartist%,Various Artists),$cutleft(%album%,6),%artist% - $cutleft(%album%,6)).m3u8,utf-8)#EXTM3U #EXTART:$if($eql(%albumartist%,Various Artists),%albumartist%,%artist%) #EXTALB:%album% $loop(%track%)$loop(%\_filename\_ext%)#EXTINF:%\_length\_seconds%,%artist% - %title% %\_filename\_ext% $loopend()$loopend() However - …

---

<div class="post-metadata">

### Author: ![gsa999](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/g/c6cbf5/32.png) [@gsa999](https://community.mp3tag.de/u/gsa999)
#### Post date: [July 6, 2020, 9:46am UTC](https://community.mp3tag.de/t/create-filename-using-replace/49554/5 "2020-07-06T09:46:09Z")

</div>

Thanks. This works. The reason I use $cutleft is because all my albums have the year, colon and space appended at the front of them so they show up in correct order on an iPod/iPhone etc. Even though I have an albumsort tag I like to see the year and album was released when playing it. I didn't want this to appear at the front of the playlist name

Thanks again

---

<div class="post-metadata">

### Author: ![gsa999](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/g/c6cbf5/32.png) [@gsa999](https://community.mp3tag.de/u/gsa999)
#### Post date: [July 6, 2020, 10:10am UTC](https://community.mp3tag.de/t/create-filename-using-replace/49554/6 "2020-07-06T10:10:39Z")

</div>

Hi, just realised I need to do the same for 2 dots (easy now) but also a single dot - which is proving a problem. I'm guessing this is because a single dot is a reserved character so the following does not work:

> $if($eql($right(%album%,1),.),.,)

Have tried the following but this also does not work  
$if($eql($right(%album%,1),\.),\.,)

How do I get it to recognise the single dot?

---

<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: [July 6, 2020, 10:18am UTC](https://community.mp3tag.de/t/create-filename-using-replace/49554/7 "2020-07-06T10:18:21Z")

</div>

What do you mean by

> [@gsa999](#):
>
> does not work:
> 
> > $if($eql($right(%album%,1),.),.,)

`$if($eql($right(any string...,1),.),.,)`  
produces, as it should, a "." as result.  
Now you have to replace it.

---

<div class="post-metadata">

### Author: ![gsa999](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/g/c6cbf5/32.png) [@gsa999](https://community.mp3tag.de/u/gsa999)
#### Post date: [July 6, 2020, 11:20am UTC](https://community.mp3tag.de/t/create-filename-using-replace/49554/8 "2020-07-06T11:20:34Z")

</div>

Basically its replacing all instances of a single dot in the filename. So "Born in the U.S.A." becomes "Born in the USA.m3u8 rather than "Born in the U.S.A.m3u8  
I have rechecked where there are 3 dots in an album title, where the 3 dots do NOT appear at the end and that works fine - i.e. the 3 dots are not replaced when not at the end but are replaced when at the end of the title

Code is now:

> $filename(%\_folderpath%$replace(%albumartist% - $cutleft(%album%,6),$if($eql($right(%album%,1),.),.,),,$if($eql($right(%album%,3),...),...,),,/,-,:, -,",'').m3u8,utf-8)

Any ideas?  
G

---

<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: [July 6, 2020, 12:52pm UTC](https://community.mp3tag.de/t/create-filename-using-replace/49554/9 "2020-07-06T12:52:41Z")

</div>

> [@gsa999](#):
>
> So "Born in the U.S.A." becomes "Born in the USA.m3u8 rather than "Born in the U.S.A

Yes, this is logical as the test is "is there a dot at the end of ALBUM?" which it is.  
And as now the dot gets restored, the replace instruction is: "replace a(ny) dot with nothing" which leads to the removal of all dots.  
So perhaps you replace the dots as final step after you did all the other processing.

---

<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: [July 7, 2020, 6:14am UTC](https://community.mp3tag.de/t/create-filename-using-replace/49554/10 "2020-07-07T06:14:17Z")

</div>

> [@ohrenkino](#):
>
> So perhaps you replace the dots as final step after you did all the other processing

Something like:  
`$regexp($replace(%albumartist% - $cutleft(%album%,6),$if($eql($right(%album%,3),...),...,),,/,-,:, -,",''),(.*)\.$,$1)`

---

<div class="post-metadata">

### Author: ![gsa999](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/g/c6cbf5/32.png) [@gsa999](https://community.mp3tag.de/u/gsa999)
#### Post date: [July 7, 2020, 9:34am UTC](https://community.mp3tag.de/t/create-filename-using-replace/49554/11 "2020-07-07T09:34:49Z")

</div>

Thanks for the suggestion. I managed to get this to work yesterday using a different technique - don't know why I didn't think of it before. Code below:

`$filename(%_folderpath%$trimright($replace,%albumartist% - $cutleft(%album%,6),/,-,:, -),.).xxx,utf-8)`

Thanks for your help  
G

---

<div class="post-metadata">

### Author: ![tor11](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/t/ebca7d/32.png) [@tor11](https://community.mp3tag.de/u/tor11)
#### Post date: [February 4, 2025, 10:06pm UTC](https://community.mp3tag.de/t/create-filename-using-replace/49554/12 "2025-02-04T22:06:39Z")

</div>

This is marginally related, but I noticed that a _regex replace_ in \_FILENAME replaces also the dot next to a file extension (.mp3) while simple _replace_ does not.

---

<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: [February 5, 2025, 6:02am UTC](https://community.mp3tag.de/t/create-filename-using-replace/49554/13 "2025-02-05T06:02:32Z")

</div>

A look at the documentation would have made this obvious:

> **[Replace with Regular Expression – Mp3tag Documentation](https://docs.mp3tag.de/actions/replace-regexp/#special-fields)**
>
> Documentation on the Replace with Regular Expression action type that can be performed as Quick Action or as reusable workflow from Action Groups. Mp3tag is the universal Tag Editor.

### Special Fields

....

- `_FILENAME` denotes the file name of the file **including its extension**

...

---

<div class="post-metadata">

### Author: ![tor11](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/t/ebca7d/32.png) [@tor11](https://community.mp3tag.de/u/tor11)
#### Post date: [February 5, 2025, 3:24pm UTC](https://community.mp3tag.de/t/create-filename-using-replace/49554/14 "2025-02-05T15:24:13Z")

</div>

Ok, I should have though of that the inconsistency is documented.

---

<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: [March 7, 2025, 3:24pm UTC](https://community.mp3tag.de/t/create-filename-using-replace/49554/15 "2025-03-07T15:24:39Z")

</div>

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