rename files

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
rosso
Posts: 1
Joined: 16 Sep 2021 14:40

rename files

Post by rosso »

Hy,

i'm new in the xyplorer community and i have already my first problem:

I have a load of files wich are named like abcd_1.pdf, efgh_2.pdf, ijkl_3.pdf and so on but i need them to be like abcd_001.pdf, efgh_002.pdf, ijkl_003.pdf,......
Is there a quick way to do that?

thanks in advance

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

Re: rename files

Post by highend »

Only doable via scripting (as long as the number part can be greater than 9)...

Select all those items and execute this:

Code: Select all

    $items = <get SelectedItemsPathNames>;
    end (!$items), "No item(s) selected, aborted!";

    $src = "";
    $dst = "";
    foreach($item, $items, <crlf>, "e") {
        if (exists($item) == 2) { continue; }
        $base  = gpc($item, "base");
        $ext   = gpc($item, "ext");
        $match = trim(regexmatches($base, "_\d+?$"), "_", "L");
        if ($match) {
            $src .= $item . <crlf>;
            $base = regexreplace($base, "^(.+?)_(\d+?)$", "$1");
            $dst .= $base . "_" . format($match, "000") . ".$ext" . <crlf>;
        }
    }
    if ($dst) {
        rename "l", trim($dst, <crlf>), "p", trim($src, <crlf>), 64;
    }
One of my scripts helped you out? Please donate via Paypal or paypal_donate (at) stdmail (dot) de

Post Reply