"Tag - Filename" creates a directory when artist name contains certain characters

Artist: C\/\/\/\
Title: Blah

Bug: On Tag - Filename using %artist% - %title%, the file is not renamed as expected. Instead, a directory is created named C with the file moved into it named - Blah.flac.

Expected: File should be renamed, and not moved into a new directory. Mp3tag should compensate by omitting these invalid filename characters. It would be nice to be able to customize this behavior and choose to either omit invalid characters (current), or replace them with a character of choice (such as _). So in this scenario, the resultant file should either be C - Blah.ext or (with requested feature) C_______ - Blah.flac.


Mp3tag v3.02 (at least present since ~v3.00, possibly earlier)
Windows 10 v2004

The characters that you list are no invalid characters - as opposed to ?* and some more..

Also see a similar description here where your observation was rated as "no bug":

Thanks for the solution. I guess I should replace all my references to %artist% to $replace(%artist%,,).

It does strike me as odd that Mp3tag wouldn't handle this by default, but rather require you to first encounter this scenario and then find a way to overcome it. Writing a title should always work in my opinion, and any advanced features (using \ for directory creation I assume) should be what requires searching online for, not for writing tags accurately. Just my opinion.

Windows reports \ / : * ? " < > | as invalid characters, but I assume you mean in Mp3tag's logic.


Or replace the slash with something that looks like a slash but isn't.
This may also avoid problems with some players that take the slash as in-field separator to create 2 entries out of one so that e.g. "AC/DC" becomes the artists "AC" and "DC".
e.g. AC⁄DC stays just one name.

I'm looking for a global solution that I don't have to think about on a per-release basis. Maybe $validate(…) will help too.

I assume $replace(%dummy%,,) replaces Mp3tag's list of invalid characters / ? * " < > | : including \?

as I said: the / and \ are valid characters in filenames and help to create folder structures from tags, see the FAQs:

So $validate() will not remove these 2 characters.

Thank you very much for the help. I think I should be able to find a solution out of the links you've provided.

I've tried adding a custom playlist filename to mirror the names of my directories but it doesn't seem to be possible:

Album name: Album \/?*"<>|:.

$replace(%album%,\,_,/,_,?,_,*,_,",_,<,_,>,_,|,_,:,_).m3u8 gives: "Playlist - Filename: Following characters are not allowed in file names: \\ / : * ? " < > |".

What works is $replace(%album%,\,_).m3u8 however all other symbols will then be replaced by nothing (which isn't what I would like in this case).

Since $replace(…) is going to…replace those symbols, it seems like a logic error in the program's code to not allow this. Wouldn't be the first time I'm wrong though.


I am not sure what you do but
gives: _________.
which looks ok to me.

In Mp3tag Options > Playlist > Filename of playlist is where the formatting doesn't work.

I just tried
which replace the "e" with an "x" and the result is:
c:\temp\Ambixnt Diary.Two_28.07.2020 160630.m3u8

Yes, using $replace() is allowed and works there, but not using the symbols / ? * " < > | : anywhere in the string. Even though $replace() would replace those symbols, Mp3tag doesn't allow them in the string I think. I cannot see a way around this. I will have to do this manually then.

I cannot very that - even though apparently one has to tweak it a little bit:
String in options:
c:\temp\$replace(%album%_%_datetime%/ ? * " < > | :,e,x,"/",_,"?",_,"*",_,",_,<,_,>,_,|,_,:,_,\,_).m3u8
Result: c:\temp\Ambixnt Diary.Two_28.07.2020 16_24_20 _ _ _ _ _.m3u8

That does seem to work. Unfortunately, it only works when an absolute path is specified. %_folderpath% cannot be used in c:\temp\'s place. It also seems necessary for \,_ to be last in the $replace() string.

My current string is (which doesn't work, but will give you an idea of my goal):
$replace([$left(%year%,4) - ][%album%],/,_,?,_,*,_,",_,<,_,>,_,|,_,:,_,\,_).m3u8

I just would like to make sure any invalid characters for Windows filenames are converted to _.

Since I cannot get this to work, for consistency's sake, I've just settled on omitting any invalid characters instead. So all I need is $replace(blah,\,) and Mp3tag will handle omitting the rest of the invalid filename characters.

Thanks for the help @ohrenkino!

%_folderpath% is an absolute path ...

YEAR should actually never be longer than 4 digits.
For more exact dates there is RELEASETIME.

That string works over here - or at least I get an underscore where I added a backslash in the album name.

Using %_folderpath% will change:
to (after automatic correction):
So even though %_folderpath is an absolute path, I can't get it to work here.

Edit: Interestingly, adding \\ to the start of \\%_folderpath%\$replace(%album%,/,_,?,_,*,_,",_,<,_,>,_,|,_,:,_,\,_).m3u8 at least allows me to OK the string without Mp3tag complaining, but when I try to write a playlist file, it shows \\C\Users\my_user\Desktop\New folder\_________.m3u8. If you notice, C\ is missing :. Not sure what's up with that.

I'm not sure how it works for you; when I try to use that string, Mp3tag complains that the "Following characters are not allowed in file names: \ / : * ? " < > |" and wants to apply an automatic correction. After I apply it, the $replace is again all underscores (like above).

All I want is an album name of \/?*"<>|: to be replaced by nine underscores _________ when creating a m3u8 playlist file. I just can't figure it out.

Assuming ID3v2.4, ID3 wiki:

TDRC (recording time) consolidates [v2.3's] TDAT (date), TIME (time), TRDA (recording dates), and TYER (year)

id3v2.4.0-frames.txt 4.2.5:

TDRC The 'Recording time' frame contains a timestamp describing when the audio was recorded. timestamp format is described in the ID3v2 structure document [ID3v2-strct].

id3v2.4.0-structure.txt 4:

… valid timestamps are yyyy, yyyy-MM, yyyy-MM-dd, yyyy-MM-ddTHH, yyyy-MM-ddTHH:mm and yyyy-MM-ddTHH:mm:ss.

… so it seems dates longer than just yyyy are fine.

I in fact don't use YEAR as it's mapped to DATE (DATE being a VorbisComment field which I like to use). If I was using ID3's convention, RELEASETIME does indeed seem to be the more accurate field to use for such info though.

I think I've finally found the solution! And kind of by luck:


For some reason, \\\\ was all that was needed to escape(?) whatever magic was happening in the background.

Playlists now created give C:\Users\my_user\Desktop\New folder\_________.m3u8.


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