Need help adding X letter if comma(,) show before dash (-) on file name.

Advanced Renamer forum
#1 : 11/04-16 06:28
John Smith
John Smith
Posts: 2
Hi, first of all, I really appreciator this program because I used it daily for my files and I thank you the creator.

I need help with and I don't know anything about JavaScript if it need to be involve

My file name: Song 1, Song 2 - A Singer, B Singer.mkv and some file some Song 1 - C Singer.mkv
What I would like to do is if there are files with a comma (,) before the dash (-), I would like to to add (LK). Example new name will be Song 1, Song 2 (LK) - A Singer, B Singer.mkv. I am working on couple hunderds files at a time

Old name: Song 1, Song 2 - A Singer, B Singer.mkv
New name: Song 1, Song 2 (LK) - A Singer, B Singer.mkv

Thanks for all your help.


11/04-16 06:28
#2 : 16/04-16 18:03
Tester123
Tester123
Posts: 92
Reply to #1:
Try this 'Script Method':

// ----- Start of Script -----
var posComma = item.name.indexOf(",");
var posDash = item.name.indexOf(" - ");
var newFilename = item.name;

if (posDash > -1 && (posDash > posComma)) {
newFilename = newFilename.replace(" - ", " (LK) - ");
}
return newFilename;
// ----- End of of Script -----

Note: This assumes there is a space on both sides of your dash, i.e. ' - ' (for search and replace consistency).


16/04-16 18:03 - edited 16/04-16 18:07
#3 : 18/04-16 10:36
joci
joci
Posts: 11
Reply to #2:

if (posDAsh > -1 && (posDash > posComma)) { etc. // This does not work
-------
change to

if (posComma > -1 && (posDash > posComma)) { etc. // This works well
--------
Have a nice day
Sincerely Jon


18/04-16 10:36
#4 : 18/04-16 23:30
Tester123
Tester123
Posts: 92
Reply to #3:
Hi, for some reason, I had it in my mind that the dash had to be present, but from what you say, it is the comma that is mandatory.

Anyway, it's good that you were able to tweak it to suit your needs.


18/04-16 23:30