# Renaming files with tag, replace trailing periods

**URL:** https://community.mp3tag.de/t/renaming-files-with-tag-replace-trailing-periods/12740
**Category:** Support
**Created:** [November 26, 2011, 2:58pm UTC](https://community.mp3tag.de/t/renaming-files-with-tag-replace-trailing-periods/12740 "2011-11-26T14:58:44Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![CheeseTurtle](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/c/ad7895/32.png) [@CheeseTurtle](https://community.mp3tag.de/u/CheeseTurtle)
#### Post date: [November 26, 2011, 2:58pm UTC](https://community.mp3tag.de/t/renaming-files-with-tag-replace-trailing-periods/12740/1 "2011-11-26T14:58:44Z")

</div>

I currently use this

E:\Music$if($neql(%albumartist%,""),$validate(%albumartist%,_),$validate(%artist%,_))$validate(%album%,_)$num(%track%,2) $validate(%title%,_)

to rename my files.

I'm trying to figure out a way to replace trailing periods in the artist and album directories with periods.

E:\Music\A.B.C\_\X.Y.Z\_\01 foo.mp3  
instead of  
E:\Music\A.B.C.\X.Y.Z.\01 foo.mp3

I'm not having any luck. Is there a way to do 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: [November 26, 2011, 3:09pm UTC](https://community.mp3tag.de/t/renaming-files-with-tag-replace-trailing-periods/12740/2 "2011-11-26T15:09:56Z")

</div>

I am not quite sure if a newly written filenames/directory name with two dots in it cause havock which is why the "validate" function removes them.  
I know that the "cd .." command means "change one directory level upwards".

have you tried to write the filenames without the validate function and what does it do to your filesystem?

---

<div class="post-metadata">

### Author: ![CheeseTurtle](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/c/ad7895/32.png) [@CheeseTurtle](https://community.mp3tag.de/u/CheeseTurtle)
#### Post date: [November 26, 2011, 3:15pm UTC](https://community.mp3tag.de/t/renaming-files-with-tag-replace-trailing-periods/12740/3 "2011-11-26T15:15:08Z")

</div>

> [@ohrenkino](#):
>
> have you tried to write the filenames without the validate function and what does it do to your filesystem?

Yeah, I did it without validate, but then AC\DC(among others) doesn't work correctly. That's why I started using $validate.

---

<div class="post-metadata">

### Author: ![JJ\_Johnson](https://community.mp3tag.de/user_avatar/community.mp3tag.de/jj_johnson/32/67_2.png) [@JJ\_Johnson](https://community.mp3tag.de/u/JJ_Johnson)
#### Post date: [November 26, 2011, 4:00pm UTC](https://community.mp3tag.de/t/renaming-files-with-tag-replace-trailing-periods/12740/4 "2011-11-26T16:00:12Z")

</div>

File and folder names in Windows may not end in periods. You can't do it. Your choice is to either leave them off or to do a character substitution. I prefer to leave them off.

---

<div class="post-metadata">

### Author: ![CheeseTurtle](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/c/ad7895/32.png) [@CheeseTurtle](https://community.mp3tag.de/u/CheeseTurtle)
#### Post date: [November 26, 2011, 4:18pm UTC](https://community.mp3tag.de/t/renaming-files-with-tag-replace-trailing-periods/12740/5 "2011-11-26T16:18:30Z")

</div>

Ok, I finally figured it out. I just replaced all the validated instances of %albumartist%, %artist%, and %album% with

$if($eql($right(_%tag%_,1),.),$regexp(_%tag%_,.$,\_),_%tag%_)

It never fails that I have to give up and ask for help right before I figure something out.

The full Convert Tag -\> Filename format string for anyone that's interested:

E:\Music$if($neql(%albumartist%,""),$validate($if($eql($right(%albumartist%,1),.),$regexp(%albumartist%,.$,_),%albumartist%),_),$validate($if($eql($right(%artist%,1),.),$regexp(%artist%,.$,_),%artist%),_))$validate($if($eql($right(%album%,1),.),$regexp(%album%,.$,_),%album%),_)$num(%track%,2) $validate(%title%,\_)

---

<div class="post-metadata">

### Author: ![DetlevD](https://community.mp3tag.de/user_avatar/community.mp3tag.de/detlevd/32/123_2.png) [@DetlevD](https://community.mp3tag.de/u/DetlevD)
#### Post date: [November 26, 2011, 4:48pm UTC](https://community.mp3tag.de/t/renaming-files-with-tag-replace-trailing-periods/12740/6 "2011-11-26T16:48:58Z")

</div>

> [@Cheese Turtle](#):
>
> ... $if($neql(%albumartist%,"") ...

What is the correct meaning of this code fragment?  
If placeholder is empty ... or ... if placeholder contains two double apostrophes?

If you need to test for the existence of any content in a placeholder, then you can code ...  
$if(%placeholder%,'yes','no')

If the first meaning is that what you want to do, then you can shorten the format string to ...

**$validate('E:\Music\'$regexp($if2(%ALBUMARTIST%,%ARTIST%),'\.+$','\_')'\'$regexp(%ALBUM%,'\.+$','\_')'\'$num(%TRACK%,2)' '%TITLE%,'\_')**

... or even better ... see following examples ...

* * *

**Examples for "Clean Path String"**

**1.**

**$validate($regexp('x ... E: \ ... Music \ ...\ ... Artist \*2\*\ Title 3 ... x','(?:^|(?\<=\\\\))[.]+|[.]+(?:(?=\\\\)|$)',),'\_')**

Result = "x ... E\_\Music\_Album 1\_\Artist _2_\Title 3 ... x"

**2.**

**$validate($regexp(' ... E: \ ... Music \ ...\ ... Artist \*2\*\ Title 3 ... ','(?:^|(?\<=\\\\))[.]+|[.]+(?:(?=\\\\)|$)',),'\_')**

Result = "E:\Music\_Album 1\_\Artist _2_\Title 3"  
Note: $validate respects the colon at the second string position.

**3.**

**$validate($regexp(' ... E: \ ... Music \ ...\ ... Artist \*2\*\ Title 3 ... ','(?:^|(?\<=\\\\))[.]+|[.]+(?:(?=\\\\)|$)',),)**

Result = "E:\Music\Album 1\Artist 2\Title 3"  
Note: $validate respects the colon at the second string position.

**4.**  
This expression might be the safest one to remove all bad characters from the given string ...

**$regexp($validate($regexp(' ... E: \ ... Music \ ...\ :.:.: ... | Artist \*2\*\ ? Title 3 ... ','(?:^|(?\<=\\\\))[.]+|[.]+(?:(?=\\\\)|$)',),),'(?:^|(?\<=\\\\))[.]+|[.]+(?:(?=\\\\)|$)',)**

Result = "E:\Music\Album 1\Artist 2\Title 3"  
Note: $validate respects the colon at the second string position.

* * *

DD.20111126.1905.CET  
Edit.  
DD.20111128.0955.CET

---

<div class="post-metadata">

### Author: ![JJ\_Johnson](https://community.mp3tag.de/user_avatar/community.mp3tag.de/jj_johnson/32/67_2.png) [@JJ\_Johnson](https://community.mp3tag.de/u/JJ_Johnson)
#### Post date: [November 26, 2011, 4:59pm UTC](https://community.mp3tag.de/t/renaming-files-with-tag-replace-trailing-periods/12740/7 "2011-11-26T16:59:13Z")

</div>

Ah, I didn't quite understand what you were trying to do. You can simplify that expression quite a bit. It's not necessary to use $if() conditionals to check for a trailing period. If the regex replacement doesn't replace a trailing period, it will simply return the original string. Also, you can select between ALBUMARTIST and ARTIST with a simple $if2() expression.

Here's the simplified expression (broken down into its parts):

```
E:\Music
\$validate($regexp($if2(%albumartist%,%artist%),\.$,_),_)
\$validate($regexp(%album%,\.$,_),_)
\$num(%track%,2) $validate(%title%,_)
```

---

<div class="post-metadata">

### Author: ![CheeseTurtle](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/c/ad7895/32.png) [@CheeseTurtle](https://community.mp3tag.de/u/CheeseTurtle)
#### Post date: [November 27, 2011, 1:55am UTC](https://community.mp3tag.de/t/renaming-files-with-tag-replace-trailing-periods/12740/8 "2011-11-27T01:55:56Z")

</div>

QUOTE (JJ Johnson @ Nov 26 2011, 12:59) \<{POST\_SNAPBACK}\>

Ah, I didn't quite understand what you were trying to do. You can simplify that expression quite a bit. It's not necessary to use $if() conditionals to check for a trailing period. If the regex replacement doesn't replace a trailing period, it will simply return the original string. Also, you can select between ALBUMARTIST and ARTIST with a simple $if2() expression.

Here's the simplified expression (broken down into its parts):

```
E:\Music
\$validate($regexp($if2(%albumartist%,%artist%),\.$,_),_)
\$validate($regexp(%album%,\.$,_),_)
\$num(%track%,2) $validate(%title%,_)<!--QuoteEnd--></div><!--QuoteEEnd-->

```

Wow, thanks. I was hoping that there was a simpler way to do it. I'm new to regex, so I didn't realize what all it could do. My way got pretty verbose.

---

<div class="post-metadata">

### Author: ![JJ\_Johnson](https://community.mp3tag.de/user_avatar/community.mp3tag.de/jj_johnson/32/67_2.png) [@JJ\_Johnson](https://community.mp3tag.de/u/JJ_Johnson)
#### Post date: [November 27, 2011, 2:44am UTC](https://community.mp3tag.de/t/renaming-files-with-tag-replace-trailing-periods/12740/9 "2011-11-27T02:44:40Z")

</div>

> [@Cheese Turtle](#):
>
> I was hoping that there was a simpler way to do it. I'm new to regex, so I didn't realize what all it could do.

Detlev hit on another simplification. You only need one $validate() function, since they all replace with an underscore.

```
E:\Music\$validate($regexp($if2(%albumartist%,%artist%),\.$,_)\$regexp(%album%,\.$,_)\$num(%track%,2) %title%,_)

```

---

<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: [November 27, 2011, 12:21pm UTC](https://community.mp3tag.de/t/renaming-files-with-tag-replace-trailing-periods/12740/10 "2011-11-27T12:21:40Z")

</div>

> [@Cheese Turtle](#):
>
> Yeah, I did it without validate, but then AC\DC(among others) doesn't work correctly. That's why I started using $validate.

I am glad that in the meantime your problem got solved.  
Yet, i would like to add a footnote on AC/DC: after I experienced trouble with AC/DC and Colourbox M/A/R/R/S and the slash this forum was very helpful to point me to a special character that looks like the slash but isn't. This way I do not have to temper with the look of artist's names. And the filesystem does not go mad (as well as WMP does not create an artist AC and one named DC ...).

---

<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:23pm UTC](https://community.mp3tag.de/t/renaming-files-with-tag-replace-trailing-periods/12740/11 "2026-02-09T12:23:28Z")

</div>


