Rename Audio Track

Javascript renaming examples. Javascript renaming is supported in version 3 or newer.

Rename Audio Track

Postby agon024 » Wed Dec 06, 2023 7:27 pm

So I want to renme multiple audio tracks

FROM
10. Black Hole Sun_Soundgarden

TO
10. Soundgarden_Black Hole Sun

I found this in here
Code: Select all
var char2find = "_";
var index = name.lastIndexOf(char2find);
newName = name.substr(index+1) + char2find + name.substr(0,index);


But that moves the band name in front of the number. I have tried to tweak it to fit my needs but have come up short.

Can some let me know what I am doing wrong? Any help is greatly appreciated.
agon024
 
Posts: 1
Joined: Wed Dec 06, 2023 7:22 pm

Re: Rename Audio Track

Postby therube » Wed Dec 06, 2023 9:39 pm

(Not that I know about such things - at all, but...)

Try something like:
Code: Select all
newName = name.substr(0,3) + name.substr(index+1) + char2find + name.substr(4, index);


with the idea that
(0,3) is your track number., so 10.
index+1 is your band name
substr(4, index) is all else

now, I don't know the syntax, & maybe the numbers are off by one (which happens to be the name of a web browser ;-)), so instead of (0,3) you might need (0,4) & if that is so, you might need substr(5, index) - or you might need to go the other way, so (0,2) & substr(3, index).


Play around & see if anything like that gets you going.
(Aside from JavaScript, you can likely do the same with RegEx:.)
therube
 
Posts: 1319
Joined: Mon Jan 18, 2016 6:23 pm


Return to Javascript Renaming


cron