Shorten Folder/File Names

Advanced Renamer forum
#1 : 01/03-25 20:12
Untalented
Posts: 2
Is it possible to reduce the length but only if the full path is 255 characters or perhaps only if the file or folder is over a certain number of characters? Or shrink a folder/subfolder set to a hard limit of a certain character count?

edited: 01/03-25 20:14
#2 : 01/03-25 23:10
Delta Foxtrot
Posts: 436
Reply to #1:

Hello,

You can use a script to do something like this:

oldName = item.name;
name = item.newBasename;
path = item.path;
if ( path.length + name.length >= 250 ) {
return oldName;
}

Put it at the end of your method list and, if the path plus new name are greater than or equal to 250 characters, it reverts to the original name before any changes. Or if you're creating much longer filenames but can afford to lose characters off the tail end, you could do something like:

totLen = 250;
name = item.newBasename;
nLen = name.length;
path = item.path;
pLen = path.length;
spare = totLen - pLen;
if ( pLen + nLen >= totLen ) {
return name.substr( 0, spare ).trim() ;
} else {
return name ;
}

This one calculates how many characters you can have without hitting the limit (totLen) and shortens the filename to fit that limit.

Best I can do without more information. Let us know if you can specify more exactly what you're thinking.

BTW, I've only marginally tested this because I don't have any paths near that long. I did take some long paths (gt 120) and created a new name for files that quadrupled their length, and it *seemed* to work for those. Nonetheless, watch the preview name column and be ready to undo the batch if necessary.

EDIT: I added the .trim() function to the second script to remove spaces at the ends of the new name in case the cut-off lands on a space. END EDIT

Best,
DF

edited: 01/03-25 23:49
#3 : 03/03-25 13:52
Untalented
Posts: 2
Reply to #2:
Thank you so much! I'll test/play around with this and see what it looks like.
#4 : 03/03-25 14:14
Kim Jensen
Administrator
Posts: 962
I will make sure that the next version can do this without using a script. Instead it will be possible to do with a method condition.