query first 'n' identical characters in a foldername

Discussion related to "Everything" 1.5 Alpha.
Post Reply
kazzybash
Posts: 110
Joined: Mon Mar 02, 2020 9:55 pm

query first 'n' identical characters in a foldername

Post by kazzybash »

hi all, is there (in a collection of folders within one parent folder) an easy syntax to query:

show all folders of which the first 5 characters in the foldername are identical?

regards, kazzy
void
Developer
Posts: 16733
Joined: Fri Oct 16, 2009 11:31 pm

Re: query first 'n' identical characters in a foldername

Post by void »

left($parent-name:,5)==left($name:,5)

You may also want to limit your name length to >= 5
Otherwise, a length of 1,2,3 or 4 may also match.

len:>=5 left($parent-name:,5)==left($name:,5)

expressions
kazzybash
Posts: 110
Joined: Mon Mar 02, 2020 9:55 pm

Re: query first 'n' identical characters in a foldername

Post by kazzybash »

hello David, thanks a lot for your kind reply and code. I tried the query, but it did not yet do what I am looking for. This must be due to my explanation probably :) .

Please see the foldertree zipped in the attachment, it contains only totally empty folders/subfolders.

When I run the query with 'testtree' selected in my left pane, I aim to get results containing folders starting with 'A' 'H' 'I' 'J' and 'X'. The folders with those names are longer than 5 characters and the first 5 of their respective names are identical. I do not want to be shown any subfolder.

I just wanna express gratitude for your loyal support, any response is not taken for granted. Thanks a lot! Regards, kazzy
Attachments
Testtree.zip
(4.94 KiB) Downloaded 254 times
NotNull
Posts: 5461
Joined: Wed May 24, 2017 9:22 pm

Re: query first 'n' identical characters in a foldername

Post by NotNull »

Lot clearer now, but not entirely ...

When you want A..12345678 and A..12876543 to be considered "equal", but not B..12345678:

Code: Select all

"C:\your\starting folder\"   folder:regex:"^(.{5})"    startwith:sibling-folder:$1:  sort:path
(this is your actual request, but I suspect you're after the following:)

When you want A..12345678 , B..12345678 and A..12345876 to be considered equal, but not A..12876543 :

Code: Select all

"C:\your\starting folder\"   folder:regex:"^[a-z]\.\.(.{5})"    regex:sibling-folder:^[a-z]\.\.$1:  sort:path


The following might work too. Will show "equal" folders grouped (I think; untested)

Code: Select all

regex:"^(.{5})"     dupe:path;regmatch1
respectively

Code: Select all

regex:"^[a-z]\.\.(.{5})"     dupe:path;regmatch1
therube
Posts: 4972
Joined: Thu Sep 03, 2009 6:48 pm

Re: query first 'n' identical characters in a foldername

Post by therube »

I don't think any of them are doing it (with most not returning results).


I was thinking (& not that I'm good with this) of something like, dupe:left($name:,5), but that too is incorrect.
NotNull
Posts: 5461
Joined: Wed May 24, 2017 9:22 pm

Re: query first 'n' identical characters in a foldername

Post by NotNull »

Did you test with the files provided by @kazzybash in testtree.zip?

EDIT: made a typo: a "z" fell off. ( [a-] instead of [a-z] ) Please try again.
(thanks for testing, btw!)
therube
Posts: 4972
Joined: Thu Sep 03, 2009 6:48 pm

Re: query first 'n' identical characters in a foldername

Post by therube »

Oh, I had PATH: enabled (which I typically do), so that skewed my results, so yes, you've got it.

With,
folder:regex:"^[a-z]\.\.(.{5})" regex:sibling-folder:^[a-z]\.\.$1: sort:path
that still returns (for example) B..0499965078 (which I don't think he wants)

With,
regex:"^[a-z]\.\.(.{5})" dupe:path;regmatch1
that skipped over the "dots" (..), so returns unwanted (though accurate per the query) results

Pretty sure,
folder:regex:"^(.{5})" startwith:sibling-folder:$1: sort:path
regex:"^(.{5})" dupe:path;regmatch1
does it, A H I J X (is that what is said above?)


With this version,
regex:"^(.{5})" dupe:path;regmatch1
and with, dupe_lines=1 (enabled in Preferences), that adds "lines" between the dup'd set, making it nicer to view (for me at least)
NotNull
Posts: 5461
Joined: Wed May 24, 2017 9:22 pm

Re: query first 'n' identical characters in a foldername

Post by NotNull »

therube wrote: Wed Mar 20, 2024 6:48 pm that still returns (for example) B..0499965078 (which I don't think he wants)
There is a C..0499965078.3 folder, so I would expect B.. to be included

(the second variation "ignores" the letter-dot-dot part at the beginning and focuses on the first 5 numbers after that to decide which foilders are "equal" )
kazzybash
Posts: 110
Joined: Mon Mar 02, 2020 9:55 pm

Re: query first 'n' identical characters in a foldername

Post by kazzybash »

Hi NotNull, therube,

this one below does it, that is what I was looking for (not the variant with "B.." being skipped, although I do understand where you're coming from).
NotNull wrote: Wed Mar 20, 2024 6:21 pm When you want A..12345678 and A..12876543 to be considered "equal", but not B..12345678:

Code: Select all

"C:\your\starting folder\"   folder:regex:"^(.{5})"    startwith:sibling-folder:$1:  sort:path
(this is your actual request...)
Then this one is a refinement and, @therube, indeed the lines make it nicer! :

regex:"^(.{5})" dupe:path;regmatch1
and with, dupe_lines=1 (enabled in Preferences), that adds "lines" between the dup'd set, making it nicer to view (for me at least)


Thanks a LOT!! :)

Regards, Kazzy
kazzybash
Posts: 110
Joined: Mon Mar 02, 2020 9:55 pm

Re: query first 'n' identical characters in a foldername

Post by kazzybash »

hi, the regex works very well, a big thanks once more!

A follow up on this thread. The expression below (and above) is giving me: "the first 5 characters must be identical"

regex:"^(.{5})" dupe:path;regmatch1


Would the following be possible and if so, how: "the first 5 characters must be identical" BUT "if first 3 are "00 " then start counting at character position 4"

What I am aiming at is that those two folders (or files, doesn't matter) show up in the results:

00 Software
Software

or

00.SnazzyDinDin
Snazzy



You get the deal I guess. Thanks a lot in advance, Kazzy
void
Developer
Posts: 16733
Joined: Fri Oct 16, 2009 11:31 pm

Re: query first 'n' identical characters in a foldername

Post by void »

Please try the following:

regex:^(?:00\s)?(.{5}) dupe:path;regmatch1

(?:...) = group and disable capture.
\s = match a space.
? = only match preceding element if it exists.
kazzybash
Posts: 110
Joined: Mon Mar 02, 2020 9:55 pm

Re: query first 'n' identical characters in a foldername

Post by kazzybash »

Hello void, thanks a lot for your reply (3 months ago :oops: ), I haven't been around for a while and never noticed you replied apparently. Just tried your suggestion/solution and it works like a charm! Kind regards, kazzy
kazzybash
Posts: 110
Joined: Mon Mar 02, 2020 9:55 pm

Re: query first 'n' identical characters in a foldername

Post by kazzybash »

As said this query works exactly how it should, great (and more than I could ask for).

Maybe it is too theoretical a question, but how come the 'sorting process' follows path? Put differently: how come 'first 'n' identical characters in a foldername' cannot identify across several (two or more) folders?

Kind regards, Kazzy
void
Developer
Posts: 16733
Joined: Fri Oct 16, 2009 11:31 pm

Re: query first 'n' identical characters in a foldername

Post by void »

Everything sorts by path + regmatch1

This sort is done to find your duplicates
Change the sort order with the sort: search function.



Use the following if you don't want to match files in the same location:
regex:^(?:00\s)?(.{5}) dupe:regmatch1
kazzybash
Posts: 110
Joined: Mon Mar 02, 2020 9:55 pm

Re: query first 'n' identical characters in a foldername

Post by kazzybash »

thank you David!!
Post Reply