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.
RegEx Help - Match Exact Paths, How?
-
SkyFrontier
- Posts: 2341
- Joined: 04 Jan 2010 14:27
- Location: Pasárgada (eu vou!)
RegEx Help - Match Exact Paths, How?
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...
-
klownboy
- Posts: 4462
- Joined: 28 Feb 2012 19:27
- Location: Windows 11, 25H2 Build 26200.8737 at 100% 2560x1440
Re: RegEx Help - Match Exact Paths, How?
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.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.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
Code: Select all
listfolder([path=<curpath>], [pattern=*], [flags], [separator="|"])Code: Select all
$ThemeList = listfolder("<xyscripts>\Themes", "*.ini", 1 + 4, "|");Good luck,
Ken
-
SkyFrontier
- Posts: 2341
- Joined: 04 Jan 2010 14:27
- Location: Pasárgada (eu vou!)
Re: RegEx Help - Match Exact Paths, How?
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.
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.
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...
-
highend
- Posts: 14954
- Joined: 06 Feb 2011 00:33
- Location: Win Server 2022 @100%
Re: RegEx Help - Match Exact Paths, How?
I don't get it...
You want to list || replace a _specific_ path by <some kind of regex>?
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;One of my scripts helped you out? Please donate via Paypal
-
SkyFrontier
- Posts: 2341
- Joined: 04 Jan 2010 14:27
- Location: Pasárgada (eu vou!)
Re: RegEx Help - Match Exact Paths, How?
bingo.
Thank you very much, highend!
Thank you very much, highend!
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...
XYplorer Beta Club