Page 1 of 1

Script to do multiple pass rename

Posted: 05 Jun 2017 10:29
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 ??

Re: Script to do multiple pass rename

Posted: 05 Jun 2017 11:12
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...

Re: Script to do multiple pass rename

Posted: 06 Jun 2017 08:54
by jaywalker32
what is the ._ notation used for in "._$oddChars" ?

Re: Script to do multiple pass rename

Posted: 06 Jun 2017 08:58
by highend
A typo :) The dot should have been a space...

Re: Script to do multiple pass rename

Posted: 06 Jun 2017 11:45
by jaywalker32
but still, why is it not:

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

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

Re: Script to do multiple pass rename

Posted: 06 Jun 2017 12:13
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

Re: Script to do multiple pass rename

Posted: 06 Jun 2017 13:12
by jaywalker32
ooh! I was overthinking it. I didn't realize that he also wanted to replace space and underscore with hyphen as well.

Re: Script to do multiple pass rename

Posted: 22 Jun 2017 08:13
by clarkedesign
OK, so how can I then assign it to the right hand mouse menu or a menu item or a keyboard shortcut ??

Re: Script to do multiple pass rename

Posted: 22 Jun 2017 08:23
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?