SongKong Jaikoz

SongKong and Jaikoz Music Tagger Community Forum

Track File Renaming

Hi. I have ZERO knowledge in Java script so I need some help please. Currently I am using the script below to rename my track files as:

Track Number - Track Title

function pad(number, length) {
      if (number == '') { return '';} 
      var str = '' + number; 
      while (str.length < length) {  
          str = '0' + str;
      }
      return str;
  }
 
 function ifnotempty(value,sep){
     return value.length > 0 ? value + sep : '';
 }
 
 function ifnotempty2(value1,value2,sep){
     return value1.length > 0 ? value1 + sep :value2.length > 0 ? value2 + sep:'' ;
 }
 
ifnotempty(pad(trackno,2),' - ') + title

That works perfectly for single disc releases. What I am trying to work up is IF there is more than one disc in the release, I want to add a padded disc number before the track number. For example:

Disc Number-Track Number - Track Title

otherwise if only one disc, leave the original naming as is.

Hope you can help. Thanks in advance.

HI, okay i have added ifmultidisc(value) function, this only returns value if multidisc otherwise retuns nothing, then we use this is the last line, this should do as you want.

Within the example mask in Jaikoz it now gives

01-02 - Twilight

So you just replace your mask with the following

function pad(number, length) {
      if (number == '') { return '';} 
      var str = '' + number; 
      while (str.length < length) {  
          str = '0' + str;
      }
      return str;
  }
 
 function ifnotempty(value,sep){
     return value.length > 0 ? value + sep : '';
 }
 
 function ifnotempty2(value1,value2,sep){
     return value1.length > 0 ? value1 + sep :value2.length > 0 ? value2 + sep:'' ;
 }
 
function ifmultidisc(value) {
   if(disctotal>1)
   {
      return value;
   }
   else
   {
      return "";
   }
}

ifmultidisc(ifnotempty(pad(discno,2),'-'))
 + ifnotempty(pad(trackno,2),' - ') + title
1 Like

Thank you very much. This worked out perfectly! Love this application! Great work. And thank you for being so responsive.

1 Like