How to script Search and Replace functionality?

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
zBernie
Posts: 179
Joined: 08 Dec 2016 17:20

How to script Search and Replace functionality?

Post 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]);

highend
Posts: 13033
Joined: 06 Feb 2011 00:33

Re: How to script Search and Replace functionality?

Post 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, ".", " ");
One of my scripts helped you out? Please donate via Paypal or paypal_donate (at) stdmail (dot) de

zBernie
Posts: 179
Joined: 08 Dec 2016 17:20

Re: How to script Search and Replace functionality?

Post 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, ".", " ");

highend
Posts: 13033
Joined: 06 Feb 2011 00:33

Re: How to script Search and Replace functionality?

Post 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...
One of my scripts helped you out? Please donate via Paypal or paypal_donate (at) stdmail (dot) de

zBernie
Posts: 179
Joined: 08 Dec 2016 17:20

Re: How to script Search and Replace functionality?

Post 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?

highend
Posts: 13033
Joined: 06 Feb 2011 00:33

Re: How to script Search and Replace functionality?

Post by highend »

Not necessarily. If you are not sure, what your script is doing, there is a step command...
One of my scripts helped you out? Please donate via Paypal or paypal_donate (at) stdmail (dot) de

Skettalee
Posts: 75
Joined: 06 May 2019 20:27

Re: How to script Search and Replace functionality?

Post 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!

kiwichick
Posts: 543
Joined: 08 Aug 2012 04:14
Location: Pahiatua, New Zealand

Re: How to script Search and Replace functionality?

Post 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, "./ ";
Windows 10 Pro 22H2

Post Reply