Page 1 of 1
Multiple Search and Replace
Posted: 16 Jul 2020 23:03
by The-Debug-Store
Hi Guys
I need to perform 8 different search and replace operations on filenames within a folder at the same time.
Is this possible?
John
Re: Multiple Search and Replace
Posted: 16 Jul 2020 23:07
by highend
Sure, but only via scripting.
Re: Multiple Search and Replace
Posted: 17 Jul 2020 03:28
by RalphM
I could provide a very basic script if interested, which does multiple renames based on a text file with one rename declaration per line.
Re: Multiple Search and Replace
Posted: 17 Jul 2020 08:45
by The-Debug-Store
Hi Ralph
I would be most grateful if you could. I just dip in and out of XYPlorer occasionally when I need it so its a learning curve whenever I need to try something new.
John
Re: Multiple Search and Replace
Posted: 17 Jul 2020 08:50
by highend
Don't you think that you should provide a bit more details which kind of search / replace operations do you need?
Are these really 1:1 related? bird -> dog, hunter -> survivor, ...
or are they maybe pattern based? <current date> -> only keep the year, etc.
Re: Multiple Search and Replace
Posted: 17 Jul 2020 09:39
by The-Debug-Store
Of course,
I need to perform the following operations in one pass:
-thickbox_default-12x/-front
-thickbox_default-22x/-angle
-thickbox_default-32x/-back
-thickbox_default-42x/-fusion
-thickbox_default-52x/-shuttle
-thickbox_default-62x/-clicker
-thickbox_default-72x/-breadboard
Re: Multiple Search and Replace
Posted: 17 Jul 2020 09:44
by highend
Code: Select all
$find = <<<>>>
-thickbox_default-12x
-thickbox_default-22x
-thickbox_default-32x
-thickbox_default-42x
-thickbox_default-52x
-thickbox_default-62x
-thickbox_default-72x
>>>;
$replace = <<<>>>
-front
-angle
-back
-fusion
-shuttle
-clicker
-breadboard
>>>;
$itemList = listfolder(, , 1+4, <crlf>);
$pattern = replacelist($itemList, $find, $replace, <crlf>);
rename "l", $pattern, "p", $itemList, 64;
Re: Multiple Search and Replace
Posted: 17 Jul 2020 09:58
by The-Debug-Store
Thanks, Highland. That was more complicated than I expected!
To run the script, I want to be able to select a group of files in a Window, then apply the script.
What is the best way of storing the script then applying it, once the files have been selected?
Re: Multiple Search and Replace
Posted: 17 Jul 2020 10:04
by highend
Replace $itemList = listfolder(, , 1+4, <crlf>); with $itemList = <get SelectedItemsNames <crlf>>;
The best way? Save the script as a file in XYs script folder and load it via a catalog entry, from a toolbar button or a user defined command (and assign a keyboard shortcut)
Re: Multiple Search and Replace
Posted: 17 Jul 2020 16:10
by RalphM
highend's version is probably more refined than my script, so I leave it at that.
Re: Multiple Search and Replace
Posted: 17 Jul 2020 16:14
by The-Debug-Store
OK, Ralph. I appreciate the offer though. Thank you. Highlands' script is now working just fine.