Page 1 of 1

RegEx Help - Match Exact Paths, How?

Posted: 14 Mar 2014 00:51
by SkyFrontier
Hi, guyz.

I need to locate all occurrences of a given path in a source, say 'C:\TEMP2\xyplorer\', listing then. RegEx could be the fastest answer, but all solutions I found allow to match all 'x:\folder1\folder2', which is not what I need.

Then I need, in sequence, to replace that same string to another one. As this may or may not be achieved by the same RegEx method (but inverted), I thought it would be better place the request inline here.

>replace() is not a valid solution as it's being by far slower than regexreplace(), in such cases.

>>'C:\TEMP2\xyplorer\SUBFOLDER\(and so on, with or without files)' *may* or *may not* be of interest, so I'd like to have a method to deal with them, too, ie, reporting them AND replacing them in a later stage.

>>>those occurrences can be anywhere in source.

Thanks in advance.

Re: RegEx Help - Match Exact Paths, How?

Posted: 14 Mar 2014 02:15
by klownboy
Hi SkyFrontier, would "listfolder()" get you a step closer? It seems to be very fast. You can use flags to give the result in folders only or files or both.

Code: Select all

listfolder([path=<curpath>], [pattern=*], [flags], [separator="|"])
I just used it today when tweaking the theme.xys script. In this case I was only retrieving the ini files in a themes folder.

Code: Select all

$ThemeList = listfolder("<xyscripts>\Themes", "*.ini", 1 + 4, "|");
Is the replacement string something that will be different in each case or different depending on the results of the folder/file lists? It's probably more complicated than I'm imagining, but could you simply use a "foreach" loop on the resultant list and an "if" statement to see if the each folder/file in the folder path contains what you're looking for and take the action...maybe using "rename" or "renameitem()".
Good luck,
Ken

Re: RegEx Help - Match Exact Paths, How?

Posted: 14 Mar 2014 02:59
by SkyFrontier
Hello, Ken.

Reports on large folder structures, previously stored in log files or the actual 'live' thing needing mid-processing prior to writing final logs. Or redirecting.
listfolder() is at earlier stages.

Re: RegEx Help - Match Exact Paths, How?

Posted: 14 Mar 2014 08:55
by highend
I don't get it...

You want to list || replace a _specific_ path by <some kind of regex>?

Code: Select all

 $paths = <<<>>>
C:\TEMP2\xyplorer\
def C:\TEMP2\xyplorer\
geh C:\TEMP2\xyplorer\hallowelt
>>>;
 
 $a = regexmatches($paths, "(C:\\TEMP2\\xyplorer)", "|");
 $b = regexreplace($paths, "(C:\\TEMP2\\xyplorer)", "test");
 text $a;
 text $b;

Re: RegEx Help - Match Exact Paths, How?

Posted: 14 Mar 2014 12:17
by SkyFrontier
bingo.
Thank you very much, highend!