Script to do multiple pass rename

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
clarkedesign
Posts: 71
Joined: 14 Feb 2013 09:29

Script to do multiple pass rename

Post by clarkedesign »

HI,

I love using XYplorer to rename files, but I want to create a script that can do multiple things at the same time, as always seem to have to make several passes on file names to get them right for my use.

I want to convert them to lower case
then replace space and underscores with hyphens
then replace a range of odd characters with hyphens

Can anyone help me write a script, then assign it to the right hand mouse menu or a menu item or a keyboard shortcut ??
Thanks,
Sean Clarke

highend
Posts: 15003
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Script to do multiple pass rename

Post by highend »

Code: Select all

    // Do not separate your "odd" chars from another!
    $oddChars = "δζ";

    foreach($item, <get SelectedItemsNames |>) {
        $item = recase($item, "l");
        $base = gpc($item, "base");
        $ext  = "." . gpc($item, "ext");
        $new  = replacelist($base, " _$oddChars", "-") . $ext;
        if ($new != $item) { renameitem($new, $item); }
    }
Renaming each file on it's can be a slow process if A LOT are selected...
One of my scripts helped you out? Please donate via Paypal

jaywalker32
Posts: 214
Joined: 27 May 2014 05:24

Re: Script to do multiple pass rename

Post by jaywalker32 »

what is the ._ notation used for in "._$oddChars" ?

highend
Posts: 15003
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Script to do multiple pass rename

Post by highend »

A typo :) The dot should have been a space...
One of my scripts helped you out? Please donate via Paypal

jaywalker32
Posts: 214
Joined: 27 May 2014 05:24

Re: Script to do multiple pass rename

Post by jaywalker32 »

but still, why is it not:

replacelist($base, $oddChars, "-")

Do the quotes and underscore around $oddChars serve a special case?

highend
Posts: 15003
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Script to do multiple pass rename

Post by highend »

By default I wouldn't call a space or an underscore an "odd char"
So he should define his real "odd chars" inside the variable $oddChars
And the replaclist() will then replace the combined ones alltogether
One of my scripts helped you out? Please donate via Paypal

jaywalker32
Posts: 214
Joined: 27 May 2014 05:24

Re: Script to do multiple pass rename

Post by jaywalker32 »

ooh! I was overthinking it. I didn't realize that he also wanted to replace space and underscore with hyphen as well.

clarkedesign
Posts: 71
Joined: 14 Feb 2013 09:29

Re: Script to do multiple pass rename

Post by clarkedesign »

OK, so how can I then assign it to the right hand mouse menu or a menu item or a keyboard shortcut ??
Thanks,
Sean Clarke

highend
Posts: 15003
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Script to do multiple pass rename

Post by highend »

to the right hand mouse menu or a menu item
Not possible
keyboard shortcut
Menu - User - Manage Commands - Run Script or Load Script File?
One of my scripts helped you out? Please donate via Paypal

Post Reply