But one problem with this approach is you have to check the length of the field first and then only substring it if its too long, because if it is not long enough substring() would give an error. This can make more complex rename masks a little unwieldy.
i.e.
This code checks the album field length is greater than 100 and if it then substrings it otherwise it just outputs the value as is.
(album.length>100 ? album.substring(0,100):album)
1. So lets make this simpler by creating a function, open up your rename mask for editing and then select the Add button at the bottom of window,
2. Now create the following function as shown in the window, then select OK.
function substring(value,length){
return value.length > length ? value.substring(0, length) : value;
}
3. Now we can use this new function in any rename mask, we simply put substring() around any value we want to limit the length of, and no longer need to check the length first.
i.e. here we use substring on albumartist, artist, title and year fields.
ifnotempty(substring(albumartist,50),' - ')
+ ifnotempty(substring(album,50),' ')
+ '(' + substring(year,4) +')/'
+ ifnotempty(pad(trackno,2),' - ')
+ ifnotempty(substring(artist,50),' - ')
+ substring(title, 50)
4. You can also use substring to simply truncate the total replaceable path by wrapping substring() around whatever you want to truncate.
i.e convert this mask:
ifnotempty2(albumartist,artist,' - ')
+ ifnotempty(album,' - ')
+ ifmultidisc(ifnotempty(pad(discno,2),' - '))
+ ifnotempty(pad(trackno,2),' - ')
+ title
to be no longer than 200 characters with:
substring(
(ifnotempty2(albumartist,artist,' - ')
+ ifnotempty(album,' - ')
+ ifmultidisc(ifnotempty(pad(discno,2),' - '))
+ ifnotempty(pad(trackno,2),' - ')
+ title),200)
No comments:
Post a Comment