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.
rename selected files
Re: rename selected files
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
Re: rename selected files
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
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
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
Re: rename selected files
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
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
XYplorer Beta Club