Renaming files with tag, replace trailing periods


#1

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?


#2

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?


#3

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


#4

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.


#5

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%,_)


#6

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


Tag to filename, replacing invalid characters with user specified ones
Konverter -> Tag-Dateiname
#7

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%,_)

#8
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.


#9

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%,_)

#10

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 ...).