Help with smart truncating of long filenames

259 characters max. length for a filepathname in a subfolder of a disk.

For extension '.flac' ...
254 characters max. length of filepathname without extension.

For extension '.mp3' ...
255 characters max. length of filepathname without extension.

Action : Format value
Tag-Field : _FILENAME
Formatstring:

$ifgreater($len(%_folderpath%$if2(%ALBUMARTIST%,%ARTIST%)[' - '%ALBUM%][' - '$num(%TRACK%,2)]' - '$if2(%TITLE%,'(Untitled)')),$sub(259,1,$len(%_extension%)),$regexp($left(%_folderpath%$if2(%ALBUMARTIST%,%ARTIST%)[' - '%ALBUM%][' - '$num(%TRACK%,2)]' - '$if2(%TITLE%,'(Untitled)'),$sub(259,2,$len(%_extension%))),'\s+$',)'…',%_folderpath%$if2(%ALBUMARTIST%,%ARTIST%)[' - '%ALBUM%][' - '$num(%TRACK%,2)]' - '$if2(%TITLE%,'(Untitled)'))

... or written into two steps ...

Action : Format value
Tag-Field : TMP_FILENAME
Formatstring:

%_folderpath%$if2(%ALBUMARTIST%,%ARTIST%)[' - '%ALBUM%][' - '$num(%TRACK%,2)]' - '$if2(%TITLE%,'(Untitled)')

Action : Format value
Tag-Field : _FILENAME
Formatstring:

$ifgreater($len(%TMP_FILENAME%),$sub(259,1,$len(%_extension%)),$regexp($left(%TMP_FILENAME%,$sub(259,2,$len(%_extension%))),'\s+$',)'…',%TMP_FILENAME%)

DD.20141231.1828.CET, DD.20150311.1024.CET, DD.20150320.1049.CET