Page 1 of 1

Truncating names of selected files

Posted: 26 Jan 2019 16:24
by DixieCup48
Would like to have a RegEx or a script (as needed) that would take a list of selected file(s) and truncate the name to X characters but leave the extension untouched. Have tried several Scripting Commands to do this which initially seemed so simple but they have all ended in spectacular failure. :cry:

Re: Request help with one task

Posted: 26 Jan 2019 16:35
by highend
Have tried several Scripting Commands
And you aren't posting them, because...?

Code: Select all

    $max = 8;

    foreach($item, <get SelectedItemsPathNames |>, , "e") {
        $base = gpc($item, "base");
        if (strlen($base) > $max) { renameitem(gettoken($base, $max, "", , 1), $item, 1+4); }
    }

Re: Truncating names of selected files

Posted: 26 Jan 2019 18:25
by DixieCup48
To highend:

Nota bene - Primus: Thank you for taking the time to fabricate the code. Does precisely what was needed!

Nota bene - Secundus: "And you aren't posting them, because...?" Doing so would have only demonstrated my puerile level of scripting experience. We have not all been blessed with your level of technical acumen.

Re: Truncating names of selected files

Posted: 26 Jan 2019 18:44
by highend
Doing so would have only demonstrated my puerile level of scripting experience
What it would have demonstrated is what logic you've tried to use to solve the problem and scripting is 80% logic and only 20% coding (finding the right commands and reading their help file entries)

Re: Truncating names of selected files

Posted: 28 Jan 2019 14:18
by DixieCup48
...and scripting is 80% logic and only 20% coding...
Your observation closely parallels one made by Thomas Edison: Invention is 10% inspiration and 90% perspiration.

That said, you premise is well taken. Will keep that in mind before making the next (infrequent) post. :biggrin:

Has there been a code change?

Posted: 28 Sep 2019 21:36
by DixieCup48
Autumnal greetings highend,

To be concise wonder if Don has made changes to XY since you authored the script. It no longer works. Instead get an Error Message stating, "Invalid Image File". :cry: