SongKong Jaikoz

SongKong and Jaikoz Music Tagger Community Forum

Sanitize a name with "/"

Hi Paul,

I don’t think this is really a bug, yet I don’t know if there is a standard way to fix this.

Having a release with a slash in album’s name, when renaming the files, it creates an unwanted subfolder.
See screenshot:

My filename mask is using ifnotempty(album,'/').
Cheers

What platform is this on?

Windows 11 (that’s why “/” creates a subfolder).

Ah maybe that’s the issue I’m not aware of this / as well as \ on Windows 11?

Yes, it seems that W11 doesn’t accept anymore / in pathname.
Maybe it’s because I enabled WSL?

image
Me, trying to add a “/” for renaming the folder “81/89”

Actually Im not sure why this is happening, we already fixed this to solve the AC/DC issue.

If you go to Preferences:FileName Masks, select your mask and Edit, then modify data in Example 1 so it looks a bit like your album do you see the issue or only when run it? Because for my mask it converts any / in fieldname to - and this is done automatically by SongKong I havent coded it in the rename mask itself.

And I tried it for real on an ACDC folder so although the Album Artist is set to AC/DC the folder name is AC-DC

image

This is on Windows 10, but the conversion is made in the code so I dont think this is actually a Windows 11 issue.

Hi Paul,
I set album to “Revolver / Volver” in example 1 and, indeed, it was correctly transformed in the sample:
image
… at least visually.

I’m going to do some additional testing here to try to pinpoint the conditions under which the error could recur.

Hi Paul,

I found the issue!
It’s when using discogs_album instead of album.
Even if the sample is correctly displayed, it is not sanitized when actually renaming the file (so, from my perspective, it’s a double issue because the results from samples should exactly reproduce the renaming sequence).

This being said, have you considered replacing / by (Big solidus) instead of hyphen-minus?
It would be much more “visual” for AC⧸DC or 1⧸4 and it looks great in file explorer:
image

Good work, okay I have replicated issue and it could occur whenever using a MusicBrainz or Discogs script field rather than a regular script field - https://jthink.atlassian.net/browse/SONGKONG-2781

Solved a difficult to find bug a while ago whereby user was using FRACTIONSLASH character instead of regular slash character so was not converted to - by SongKong, however the underlying operating system did treat like a slash and removed from filename. This was very confusing and I think use of the BigSolidus character could also be confusing for the average user so I don’t want to do this.

I thought you could write a function to use BigSolidus but that would be tricky because the conversion from / to - has to be done on per field before we apply the Filename Rename mask so you cannot do it directly within Filename Rename mask as the Slash has already be converted to Hyphen before the rename mask is applied.

You could do it by use Scripter to change the value before using Filename mask because the Slash to Hyphen conversion is not done in Scripter as not necessary. For example if want to use discogs_album since it is not a regular field you could copy this value to custom1 field and apply conversion of Hyphen to Big Solidus as you do it, then use custom1 field instead of discogs_album in your rename mask.

But this is all a bit complicated so I have created an improvement issue to Replaces Slashes with option

https://jthink.atlassian.net/browse/SONGKONG-2782

Hi Paul,
Thanks for your reply.
And thanks for the path you chose to solve the issue. Indeed, a unilateral decision to replace the slash character by whatever could be confusing for many users. But having the user choosing is nice.

Proposition to extend 2782 ticket to every other forbidden filename character.

Slash is special because we use it to signify a folder so if we don’t convert it when found in metadata extra folders are created where user does not want them.

Other special characters such as * can be converted easily yourself in your rename mask.If you don’t do anything then they are automatically removed if invalid for the operating system they are being created on.

For example we create a r function that uses replaceAll to replace various characters with +. Note because ?, * and \ are special characters in replaceAll function (because it represent a regular expression) we have to escape them with the extra \ . We dont need to that for : because that is not special character for regular expressions.

We then use the r function passing our mask as parameter.

function r(value)
{
   return value
	.replaceAll("\\?","+")
	.replaceAll("\\*","+")
        .replaceAll("\\\\","+")
	.replaceAll(":","+");
}

r(albumartist + '/'
+ ifnotempty(album,'/')
+ ifnotempty(pad(discno,2),' - ')
+ ifnotempty(pad(trackno,2),' - ')
+ title);
1 Like

OK, understood.
And thanks for the solution.

Based on Windows forbidden characters, one may try and map this way:
\ ⇒ ⧹or \
/ ⇒ ⧸ or/
: ⇒ 𑁊
* ⇒ ✶
? ⇒ ⁇
" ⇒ ” (or ideally first “ and other ” as they should be paired)
< ⇒ ❮
> ⇒ ❯
| ⇒ ❘

(but, frankly speaking, I was not much worried by their disappearing, so far :wink:)

1 Like

Now fixed this in 11.7