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