Page 1 of 1
rename selected files
Posted: 22 Feb 2022 00:49
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.
Re: rename selected files
Posted: 22 Feb 2022 05:57
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);
}
Re: rename selected files
Posted: 13 Mar 2022 04:42
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
Re: rename selected files
Posted: 13 Mar 2022 04:49
by jupe
Re: rename selected files
Posted: 13 Mar 2022 06:53
by highend
So you turned working code (a simple check if enough items are selected) into nonsense?
Re: rename selected files
Posted: 17 Mar 2022 10:27
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