Starting with a simple (but probably not quite right) example, this shortens things to 30 characters while ignoring the extensions (and the length of the extensions; more on that below):
Mode: regular expressions
Old name: ^(.{30}).*
New name: \1
Some of those names are longer than 30 characters due to the extensions on the end, which weren't counted. If you know the extensions are always 4 characters then you could just use 26 as the limit, but that's probably not ideal.
You probably want to include the length of the extensions in the calculation automatically.
I'm guessing you also don't want to have any spaces before the extensions as well, as that looks a bit weird.
In that case, let's switch to using a rename script.
As a bonus, this script also gives you a field you can input your maximum length into, without having to worry about regular expressions and so on:
Now the results should be what you actually want:
Here's the rename preset, which can be used in the Rename Dialog as shown above, or in toolbar buttons, hotkeys, etc. if you want to automate things further (shout if you need help with those):
For reference, this is the rename script, which is inside that preset. You'll see it if you click "Edit" in the Rename dialog, next to where it says "Script defined" in bold.
You don't need to understand this script code to use it, but it shows you how things work if you want to do something similar in the future.
function OnGetCustomFields(getFieldData)
{
getFieldData.fields.maxLength = 30;
getFieldData.field_labels("maxLength") = "Maximum Length";
}
// This is the renaming function
function OnGetNewName(getNewNameData)
{
var stem = getNewNameData.newname_stem_m
var ext = getNewNameData.newname_ext_m
var lenMax = getNewNameData.custom.maxLength;
var lenTotal = stem.length + ext.length;
if (lenTotal > lenMax)
{
var lenNewStem = stem.length - (lenTotal - lenMax);
DOpus.Output(lenNewStem);
if (lenNewStem > 0)
{
stem = stem.substr(0, lenNewStem);
// Trim spaces from the end.
stem = stem.replace(/\s+$/, '');
return stem + ext;
}
}
return;
}