Unknown underscore when renaming files in Picard

I’m trying to batch rename a lot of music files that contain a forward slash in the %title% ID3 tag with this script:

$num(%tracknumber%,2) - $rreplace(%title%,/,-)

This renames my file to:

06 - Steve, the Emperor of Beer _ from Super Barbecue III.mp3

and this is almost perfect. I don’t know where the underscore is coming from. The original title of the track is:

Steve, the Emperor of Beer / from Super Barbecue III

The expression doesn’t change the forward slash to the expected hyphen character. I do know the script logic works because if I change the forward slash to the underscore, it will be replaced with the hyphen.

Why is the underscore being set in the first place and how do I change this?

1 Like

A slash is not allowed in a filename on whatever filesystem. Therefore / is replaced by _ and it looks like this happens before the script is executed (I haven’t known that until now)

You have to replace the replacement to get what you want:
$num(%tracknumber%,2) - $rreplace(%title%,_,-)

But the script will also replace every other character that isn’t allowed in your filesystem.

This was my experience. I could correct for the underscore, but I do have other audio files that legitimately contain that character.

I’ve created a bug report, since I think this could be handled differently to allow for my script to run.

1 Like

But it’s probably not that easy to fix. After running the script, you might have legitimate slashes in your path (for subdirectories) and Picard would have to distinguish between wanted and unwanted slashes.

The forward slash was automatically changed to an underscore without any input or settings and this behavior is unable to be changed thus, my script will not catch or replace it. It should have been replaced with a fraction slash character, which is a suitable and possible replacement.

Actually there already is a setting for this.


Copying my response from the ticket, because this is intentional behavior:

The replacement of slashes is the only one that runs before script execution. And it has to run before because it is a directory separator. It cannot run on the script result, because there are always slashes in the result to separate directories.

Because of this there is a separate option to customize the replacement character, see File Naming Compatibility Options — MusicBrainz Picard v2.11 documentation


For tag-usage it’s ok, but you should not use or want that character on folder or files by force. On most operating systems / is a special part of directory structure and thus forbidden to use. Maybe on the next device you want to use your files this leads to unforeseen consequences, in a non-harmful way it just doesn’t work or it can crash the device.

I should note that, I have made manual corrections to ‘/’ chars in track titles before saving, and that does not result in the unwanted ‘_’. So the replacement is not automatic during reading in of the album. However, like me, I’m sure nobody is too happy to have to replace each by hand. I have not seen a script to achieve this either.