rename selected files

Discuss and share scripts and script files...
Post Reply
tiger08
Posts: 10
Joined: 13 Nov 2014 08:25

rename selected files

Post by tiger08 »

I selected files of different extensions like PDF, TXT , PNG, DOC ( one file of each extension ).
I want to rename the files in such a way that basename of TXT file becomes basename of all other files(On selected files only).
e.g.
Linux For Beginners - 9th Edition, 2021.txt
Linux For Beginner.pdf
Linux For.png

like:
Linux For Beginners - 9th Edition, 2021.txt
Linux For Beginners - 9th Edition, 2021.pdf
Linux For Beginners - 9th Edition, 2021.png

Thanks and Warm Regards.

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

Re: rename selected files

Post by highend »

Code: Select all

    $items = <get SelectedItemsPathNames>;
    end (<get CountSelected> < 2), "At least 2 items must be selected, aborted!";

    $txt = regexmatches($items, "^.+?\.txt$");
    end (gettoken($txt, "count", "|") != 1), "Either none or more than one .txt file(s) selected, aborted!";

    $txtBase = gpc($txt, "base");
    foreach($item, $items, <crlf>, "e") {
        if ($item == $txt) { continue; }
        renameitem($txtBase, $item);
    }
One of my scripts helped you out? Please donate via Paypal

tiger08
Posts: 10
Joined: 13 Nov 2014 08:25

Re: rename selected files

Post by tiger08 »

Thanks for quick reply.
Sorry for delay on my part.

In the first instance the script did not worked.
I studied it thoroughly and in line 2, I changed the position of closing bracket to end.

end (<get CountSelected> < 2), "At least 2 items must be selected, aborted!"; -- line 2 as provided
end (<get CountSelected> < 2, "At least 2 items must be selected, aborted!"); .. line 2 as changed

It worked like MAGIC.
Thanking you very much,
Warm Regards,
tiger08

jupe
Posts: 3292
Joined: 20 Oct 2017 21:14
Location: Win10 22H2 120dpi

Re: rename selected files

Post by jupe »

:roll:

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

Re: rename selected files

Post by highend »

So you turned working code (a simple check if enough items are selected) into nonsense?
One of my scripts helped you out? Please donate via Paypal

tiger08
Posts: 10
Joined: 13 Nov 2014 08:25

Re: rename selected files

Post by tiger08 »

Sir,

Your remarks made me think and try afresh with cool mind today.

I do not know how it happened. Either I did not copy script to 'try script' correctly or something else.

What is strange to me that when I place the closing bracket in either position it works, which should NOT.
No errors is reported by script interpreter.
I do not understand scripts, it was a try by chance.
Some mistake on my part, I regret it.

Thanks for your understanding,
Warm Regards,
tiger08

Post Reply