Search for files within folders that match a regex pattern

Discussion related to "Everything" 1.5 Alpha.
Post Reply
omotrl
Posts: 15
Joined: Sun Oct 02, 2022 4:24 pm

Search for files within folders that match a regex pattern

Post by omotrl »

Hi,

I need to find txt files that reside in folders that have no dashes in their names. I tried

Code: Select all

ext:txt regex:!-
but it shows txt files in any folder.
horst.epp
Posts: 1443
Joined: Fri Apr 04, 2014 3:24 pm

Re: Search for files within folders that match a regex pattern

Post by horst.epp »

What about with this one
folder:regex:!- child:*.txt
omotrl
Posts: 15
Joined: Sun Oct 02, 2022 4:24 pm

Re: Search for files within folders that match a regex pattern

Post by omotrl »

This seems to display the target folders, while I need to display the txt files in those folders.
NotNull
Posts: 5458
Joined: Wed May 24, 2017 9:22 pm

Re: Search for files within folders that match a regex pattern

Post by NotNull »

omotrl wrote: Sun Jul 23, 2023 3:08 pm I need to find txt files that reside in folders that have no dashes in their names.
Do you mean
1. No "-" in the parent folder (no c:\windows\123-abc\file.txt)?
-or-
2. No "-" anywhere in the path (no c:\123-abc\windows\file.txt)?


And why regex specifically? There might be solutions without regex too.
NotNull
Posts: 5458
Joined: Wed May 24, 2017 9:22 pm

Re: Search for files within folders that match a regex pattern

Post by NotNull »

Anyway, I probably won't have time later tonight, so for scenario 2. :

Regex:

Code: Select all

regex:"^[^-]*\\[^\\]+\.txt$"
Non-regex:

Code: Select all

ext:txt   !**-**\*.txt 
omotrl
Posts: 15
Joined: Sun Oct 02, 2022 4:24 pm

Re: Search for files within folders that match a regex pattern

Post by omotrl »

No "-" in the immediate parent folder.
Modifying your non-regex, this seems to work:

Code: Select all

ext:txt   !*-*\*.txt
But what I am still interested in how to do it with regex.
NotNull
Posts: 5458
Joined: Wed May 24, 2017 9:22 pm

Re: Search for files within folders that match a regex pattern

Post by NotNull »

Non-regex alternative:

Code: Select all

ext:txt   !parentname:-
Regex (untested)

Code: Select all

regex:^.*\\[^\\-]+\\[^\\]+\.txt$ 
or

Code: Select all

regex:\\[^\\-]+\\[^\\]+\.txt$ 
but I think the first regex is faster (due to anchoring)
omotrl
Posts: 15
Joined: Sun Oct 02, 2022 4:24 pm

Re: Search for files within folders that match a regex pattern

Post by omotrl »

Great, thanks a lot!
NotNull
Posts: 5458
Joined: Wed May 24, 2017 9:22 pm

Re: Search for files within folders that match a regex pattern

Post by NotNull »

You're welcome!

Still wondering why it had to be a regex solution specifically though ..

You are definitely not the only one, but now it is the time to ask why?
(a non-regex solution is typically more straightforward)
omotrl
Posts: 15
Joined: Sun Oct 02, 2022 4:24 pm

Re: Search for files within folders that match a regex pattern

Post by omotrl »

:D You are right!
The reason for regex is somewhat convoluted and, as it turned out, completely unjustified indeed. The thing is before this particular search I did a few other searches where regex was justified, then I mechanically used regex with !-, but when I failed to produce the expected result, I knew that I needed just to add something to "regex:!-" to show that it refers to the folders. That's what I called "to do it with regex". By suggesting "parentname" you provided me with what I was looking for, getting rid of regex along the way.

But still a question on regex. Suppose I need to define parentname with regex, is it possible? Parentname:regex: doesn't seem to work.
NotNull
Posts: 5458
Joined: Wed May 24, 2017 9:22 pm

Re: Search for files within folders that match a regex pattern

Post by NotNull »

I now understand. Thanks for clarifying!

omotrl wrote: Mon Jul 24, 2023 5:07 pm But still a question on regex.
Good question!

The general syntax is search-modifier:search-function:value [1]
regex: is a search modifier, whereas parentname: is a search function.

So this should do the trick:
regex:parentname:



[1] Or search-modifier:search-modifier:search-modifier:search-function:value if you need multiple modifiers.
The order of the modifiers is not important.
omotrl
Posts: 15
Joined: Sun Oct 02, 2022 4:24 pm

Re: Search for files within folders that match a regex pattern

Post by omotrl »

Great! Thank you for the explanation!
Post Reply