You are not logged in.
I have a number of files named as pattern RELEASENAME - PERFORMER - TITLE - GENRE.EXTENSION that I'm moving to a NAS that only supports a file name length of 143 characters including the extension.
I would like to rename the files so that the only the TITLE part of the current filename is truncated but all other parts of the filename are retained.
I would very much appreciate help on how to automate this as it would save me from having to manually rename several thousand files.
Offline
This can be achieved with the Pascal Script rule.
The script below will shrink the 3rd part in the filename delimited by " - ", such that the whole filename length does not exceed MaxFileNameLength. Other parts will not be affected, so it is possible for the filename to still exceed the maximum length if other parts alone exceed it. If a filename does not match the pattern, it will be skipped.
const
MaxFileNameLength = 143;
var
Parts: TWideStringArray;
ShrinkBy: Integer;
begin
if Length(FileName) > MaxFileNameLength then
begin
Parts := SubMatchesRegEx(FileName, '\A(.+?) - (.+?) - (.+?) - (.+?)\.([^\.]+)\Z', False);
if Length(Parts) = 5 then
begin
ShrinkBy := Length(FileName) - MaxFileNameLength;
Parts[2] := WideCopy(Parts[2], 1, Length(Parts[2]) - ShrinkBy);
FileName := Parts[0] + ' - ' + Parts[1] + ' - ' + Parts[2] + ' - ' + Parts[3] + '.' + Parts[4];
end;
end;
end.
Offline