Page 1 of 2
How to script Search and Replace functionality?
Posted: 04 Apr 2022 16:50
by zBernie
I'm trying to replicate the Search and Replace functionality of './ ' (without quotes). This replaces all of the '.' characters in a file except for the one before the file extension. I've been unsuccessful using the replace() function as shown below.
$var_file = "<curname>";
$x = replace($var_file, '.', [replacement=" "], [matchcase=0], [start=1], [count=-1]);
Re: How to script Search and Replace functionality?
Posted: 04 Apr 2022 18:23
by highend
This replaces all of the '.' characters in a file except for the one before the file extension
What?
This would replace all dots, no exception^^
Code: Select all
$var_file = <curbase>;
$x = replace($var_file, ".", " ");
Re: How to script Search and Replace functionality?
Posted: 04 Apr 2022 19:21
by zBernie
highend wrote: ↑04 Apr 2022 18:23
This replaces all of the '.' characters in a file except for the one before the file extension
What?
This would replace all dots, no exception^^
Code: Select all
$var_file = <curbase>;
$x = replace($var_file, ".", " ");
I'm having difficulty executing that replace() function. When I execute it nothing happens. Like it's not even there. I tried it with the Scripting -> Run Script menu item, and also placed it in the left click section of a button. Nothing happens in either case. So, I tried adding all of those X's to generate a syntax error, and still nothing. I believe the spacing and indentation are correct. I made sure there were no extraneous whitespace characters below the code. Also, I just updated XYplorer to the latest version for good measure. Any idea why that code is not executing at all?
Code: Select all
$var_file = <curbase>;
XXXXXXXXXX
$x = replace($var_file, ".", " ");
Re: How to script Search and Replace functionality?
Posted: 04 Apr 2022 19:24
by highend
The code is executing just fine. I have no clue why you think that it would actually rename a file though. Do you see any command like rename / renameitem in your code? I don't...
Re: How to script Search and Replace functionality?
Posted: 04 Apr 2022 19:42
by zBernie
highend wrote: ↑04 Apr 2022 19:24
The code is executing just fine. I have no clue why you think that it would actually rename a file though. Do you see any command like rename / renameitem in your code? I don't...
Shouldn't the line with the XXXXXXXXX generate a syntax error?
Re: How to script Search and Replace functionality?
Posted: 04 Apr 2022 19:50
by highend
Not necessarily. If you are not sure, what your script is doing, there is a step command...
Re: How to script Search and Replace functionality?
Posted: 10 Jan 2024 03:25
by Skettalee
Hey bud did you end up figuring out the code. I think I have been trying to do the same thing. I wanted a one hand mouse button click to first turn decimals into one space and not the .ext one. Im still having a hard time doing any dang coding even though i spent most of my time in front of it. My adhd screws me up there, so if you figured that one out id love to get that code myself!
Re: How to script Search and Replace functionality?
Posted: 10 Jan 2024 08:00
by kiwichick
I regularly rename files by replacing a dot with a space, excluding the extension. This is what I use:
Code: Select all
end(getinfo("CountSelected") < 1), "Nothing selected!";
rename s, "./ ";
Re: How to script Search and Replace functionality?
Posted: 17 Aug 2024 04:16
by Skettalee
Is there a way to make the script
$var_file = <curbase>;
$x = replace($var_file, ".", " ");
$x = replace($var_file, "X", "");
$x = replace($var_file, "{", "");
$x = replace($var_file, "}", "");
$x = replace($var_file, ")", "");
$x = replace($var_file, "(", "");
to do that? Just go across the files and remove multiple patterns?
Re: How to script Search and Replace functionality?
Posted: 17 Aug 2024 09:23
by highend
Apart from there is replacelist / regexreplace for all the items where the replacement is "", why shouldn't that be possible?
A loop that stores all new names and afterwards a single rename with an "l" for the mode to do all renames in one command like in dozens of other scripts / snippets that have been posted here...
Re: How to script Search and Replace functionality?
Posted: 24 Aug 2024 00:45
by Skettalee
Im sorry but I have been reading the help file replacelist over and over trying to figure out how I use replacelist to remove multiple things and maybe im just totally stupid or missing something somewhere, I have even tried using some of the examples you have like i add the word Taxi somewhere in the file name and run command :
Code: Select all
text replacelist("Taxi", "ai", "ia"); //Tixa
yet all that the command does is pop up a window that has the text "Tixa" in it. doesn't do anything other than that, what am i doing wrong here?

- Screenshot 2024-08-23 174245.png (93.23 KiB) Viewed 2536 times
Re: How to script Search and Replace functionality?
Posted: 24 Aug 2024 02:22
by RalphM
What did you expect?
Text = open a window showing the result of your replacements
replacelist = with these two lists "ai" "ia" you are replacing all "a" with an "i" and all "i" with an "a"
So the result "Tixa" is correct.
For your earlier example you would need the following two commands for all replacements:
$var_file = <curbase>;
$var_file = replace($var_file, ".", " ");
$var_file = replacelist($var_file, "X{}()", "");
But then to actually rename selected files, you would need to create a list of selected filenames, make the replacements in the list and then rename the files with the "l" option as stated earlier.
Re: How to script Search and Replace functionality?
Posted: 24 Aug 2024 23:02
by Skettalee
Thank you for trying to clear things up for me. I expected to have the examples I see going through the scripting i am trying to figure out in the help file. I dont know why I am having such a hard time with everything other than my adhd issues make it hard to retain everything that I read, and it seems like even if I read something 5 times I still dont retain everything. Especially the more words that I have to read through, then the less I will remember what the first sentence said. And that I have had brain surgery in my early 30's and my memory has been getting worse especially short term memory.
What would someone charge me to help me understand or even just write a script for me that I can figure out how to set a number of words I want to be removed from a selection of files? At this point I think I should just pay someone because I have been trying to figure it out off and on for at least a year now with no success. Cause at this point either I have to run Advanced Renamer and have a huge list of rules in that but also still keep having to add more things. I have then written a batch file that will command line run the advanced renamer with the file full of rules. And would rather (since Ive learned about the scripting and options with replacing words) just while directly inside of XYplorer have that program do the replacing and just edit my Xys file to add more and more words I would like removed. At this point the number of rules i have in advanced renamer which also keeps growing is 463 different things to remove or replace or change spelling's or Capitalize so maybe to create the same thing in a script would be difficult but I dont know. I do now my OCD makes me want to figure it out still as well as remove having a batch file that I need to copy around or move the files to its location to run.
Re: How to script Search and Replace functionality?
Posted: 25 Aug 2024 19:00
by highend
Click on the paypal donation link in my signature, donate the suggested amount of money and I'll write you one which you can extend yourself by filling in words to replace...
Only for:
a.) Elements to replace with nothing, e.g. "folks", example: "hey folks.txt" => "hey.txt"
b.) Pairs of elements to replace, e.g. "folks<:>people", example: "hey folks.txt" => "hey people.txt"
Multiple spaces (e.g. for replacements in a.) will be reduced to a single one
E.g.: "fine", example: "weather is fine today.docx" => "weather is today.docx" (just a single space between "is" and "today", not two)
Re: How to script Search and Replace functionality?
Posted: 26 Aug 2024 04:14
by Skettalee
What is the suggested amount?