Truncating names of selected files

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
DixieCup48
Posts: 46
Joined: 30 Jan 2018 14:58

Truncating names of selected files

Post by DixieCup48 » 26 Jan 2019 16:24

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:

highend
Posts: 8363
Joined: 06 Feb 2011 00:33

Re: Request help with one task

Post by highend » 26 Jan 2019 16:35

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); }
    }
One of my scripts helped you out? Please donate via Paypal or highend (at) web (dot) de

DixieCup48
Posts: 46
Joined: 30 Jan 2018 14:58

Re: Truncating names of selected files

Post by DixieCup48 » 26 Jan 2019 18:25

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.

highend
Posts: 8363
Joined: 06 Feb 2011 00:33

Re: Truncating names of selected files

Post by highend » 26 Jan 2019 18:44

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)
One of my scripts helped you out? Please donate via Paypal or highend (at) web (dot) de

DixieCup48
Posts: 46
Joined: 30 Jan 2018 14:58

Re: Truncating names of selected files

Post by DixieCup48 » 28 Jan 2019 14:18

...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:

DixieCup48
Posts: 46
Joined: 30 Jan 2018 14:58

Has there been a code change?

Post by DixieCup48 » 28 Sep 2019 21:36

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:

Post Reply