SongKong Jaikoz

SongKong and Jaikoz Music Tagger Community Forum

how do I prevent folder names that don't end in a letter/number fromshowing up garbled on windows

My folder rename masks are Artist/AlbumArtist-album/file for non-compilations and AlbumArtist/AlbumArtist-album/file for compilations and I’m getting the randomly assigned garbled folder names (e.g. JVQVM) in Windows for every artist that doesn’t end in a letter or number (e.g. Notorious B.I.G.).

I don’t remember this happening before but whatever, its happening now. Does anyone have any suggestions for what to add to my folder rename mask to make sure the folder name doesn’t end in any character that Windows won’t recognize as the end of a folder name (I imagine it would be more than just the period in the Notorious B.I.G. example above).

I found this http://www.daniweb.com/web-development/javascript-dhtml-ajax/threads/344850/get-the-last-character-of-string-with-javascript#, is that my best bet?

Thanks!

How long is the total length of your filepath, I think this might be an issue with filepaths or possibly filenames on networked drives.

[quote=paultaylor]How long is the total length of your filepath, I think this might be an issue with filepaths or possibly filenames on networked drives.[/quote]Not long, I actually have a test in the File renaming masks for shortening the path (an issue I ran into earlier). Here’s my rename mask for sharing’s sake:

PersonalMax=150;
ShortAlbum=50;
NewAlbum=(album.length>0 ? (album.length<ShortAlbum ? album : (album.substring(0, ShortAlbum-3) + '...')) : '');
PersonalSum=(title.length+(2*NewAlbum.length)+(2*albumartist.length) + artist.length);
WhatToSubtractFromTitle=(PersonalSum-PersonalMax+3);
NewTitleLength=(title.length - WhatToSubtractFromTitle);
NewTitle=(title.length>0 ? (PersonalSum<PersonalMax ? title + ' - ' : (title.length>WhatToSubtractFromTitle ? (title.substring(0, NewTitleLength) + '... - ') : '')) : '');
(disctotal>1 ? discno + '-': '') + (trackno.length>0 ? trackno + ' - ': '') + NewTitle + (artist.length>0 ? artist + ' - ' : (albumartist.length>0 ? albumartist + ' - ' : '')) + NewAlbum

fyi: I use 150 as the “PersonalMax” to overcompensate for the possibility the music ends up nested many folders deep on some other computer.

I am 99.9999% positive this particular issue is with the final character being a period (or perhaps other non-letter-or-number characters) since every one I clicked on was an artist that ended in a period (plus all the enclosed folders and files were fine). Also, I just tried to rename a random folder on my PC to have a period at the end and the folder disappeared from Explorer.

Here’s the Folder Rename Mask I’ve come up with:

(artist.length>0 ? whichartist = artist : (albumartist.length>0 ? whichartist = albumartist : whichartist = 'noartist'));
(whichartist.charAt(whichartist.length(-1)) == "." ? artistmod = whichartist.substring(0,(whichartist.length-1)) : artistmod=whichartist);
(album.charAt(album.length(-1)) == "." ? albummod = album.substring(0,(album.length-1)) : albummod = album);
(artistmod + folderseparator) + (originalyear.length>0 ? '(' + originalyear.substring(0,4) + ') ' : (year.length>0 ? '(' + year.substring(0,4) + ') ' : '')) + (album.length>0 ? whichartist : artistmod) + (album.length>0 && (albumartist.length>0 || artist.length>0) ? ' - ' : '') + (albummod)

I haven’t been able to test it (just wrote it in notepad++) but I’m pretty sure it will work. Though only if the offending character is a period. I’d really like to change this test in the above mask:

to one that tests if the last character is NOT a letter or number. as in:

but I don’t really know how to make regex and js play well together (mostly I’m just bad at coding in general). Really, I just want to exclude any character that’s gonna cause issues if placed at the end of a folder name. So maybe I could even add underscores and dashes etc to the above regex.

Well, didn’t have much time to test it but I did throw it into Preferences and got an error (nothing showed up in the Example Mask). If you see an error please let me know…

edit: found the error. I just needed charAt(-1) not charAt(whichartist.length(-1)). So put it in with no error, but didn’t seem to replace the . at the end. I’ll keep hacking at it. Also just realized I need to loop the test for artists like The Academy is…

edit2: seems to be an issue with charAt(-1) I replaced the test of “.” with “2” and U2 was still displayed as the parent folder…

edit3: Success! Got the initial mask to work (tested on T.I.), I was right the first time with (whichartist.charAt(whichartist.length-1) just had the wrong parenthesis. ```(artist.length>0 ? whichartist = artist : (albumartist.length>0 ? whichartist = albumartist : whichartist = ‘noartist’));
(whichartist.charAt(whichartist.length-1) == “.” ? artistmod = whichartist.substring(0,(whichartist.length-1)) : artistmod=whichartist);
(album.charAt(album.length-1) == “.” ? albummod = album.substring(0,(album.length-1)) : albummod = album);
(artistmod + folderseparator) + (originalyear.length>0 ? ‘(’ + originalyear.substring(0,4) + ') ’ : (year.length>0 ? ‘(’ + year.substring(0,4) + ') ’ : ‘’)) + (album.length>0 ? whichartist : artistmod) + (album.length>0 && (albumartist.length>0 || artist.length>0) ? ’ - ’ : ‘’) + (albummod)

So now I need to add a for loop for multiple undisplayable characters and for it to test for more than just "."

edit4: After some googlin' I discovered a 'while' loop is more appropriate than a 'for'.  Untested, but here's where I'm at:```(artist.length>0 ? whichartist = artist : (albumartist.length>0 ? whichartist = albumartist : whichartist = 'noartist'));
artistmod = whichartist;
while (artistmod.charAt(artistmod.length-1) == ".") {artistmod = artistmod.substring(0,(artistmod.length-1));};
albummod = album;
while (albummod.charAt(albummod.length-1) == "." ) {albummod = albummod.substring(0,(albummod.length-1));};
(artistmod + folderseparator) + (originalyear.length>0 ? '(' + originalyear.substring(0,4) + ') ' : (year.length>0 ? '(' + year.substring(0,4) + ') ' : '')) + (album.length>0 ? whichartist : artistmod) + (album.length>0 && (albumartist.length>0 || artist.length>0) ? ' - ' : '') + (albummod)

Please please please tell me to shut up if this is more annoying than useful to the forum/Jaikoz community:)
edit5: I found this link
http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx#file_and_directory_names
and it appears it is JUST the period that is the issue (because you designate directory components by starting the path with a period). So if this while loop works, I’m DUN done.
edit6: Success! it works, I also completely overhauled my title shortening mask. I’ll post them in the mask example thread.