List a part of path

If you are experiencing problems with "Everything", post here for assistance.
Post Reply
sk2107
Posts: 326
Joined: Sun Aug 07, 2022 8:48 pm

List a part of path

Post by sk2107 »

Hello,

I need to list a certain part of the folders, for example:

c:\aaaa\bbbb\cccc\ddd\xyz
c:\aaaa\bbbb\eee\ddd\xyzx
c:\aaaa\bbbb\eee\dddz\xyze
c:\aaaa\bbbb\ttttttt\ddered\sxyz

So, I want to have a column with c:\aaaa\bbbb or any required depth regardless the value of the rest of the path.

Best regards
void
Developer
Posts: 16770
Joined: Fri Oct 16, 2009 11:31 pm

Re: List a part of path

Post by void »

To add a column to show the first 3 parts of the path, include the following in your search:

addcolumn:a a:=regexextract($path:,"^[^\\]*(?:$|\\[^\\]*(?:$|\\[^\\]*))")



To add a column to show the first 2 parts of the path, include the following in your search:

addcolumn:a a:=regexextract($path:,"^[^\\]*(?:$|\\[^\\]*)")



To add a column to show the first 4 parts of the path, include the following in your search:

addcolumn:a a:=regexextract($path:,"^[^\\]*(?:$|\\[^\\]*(?:$|\\[^\\]*(?:$|\\[^\\]*)))")



regex-extract()



edit:

addcolumn:a a:=regexextract($path:,"(?:(?:^|\\)[^\\]*){3}")
addcolumn:a a:=regexextract($path:,"(?:(?:^|\\)[^\\]*){2}")
addcolumn:a a:=regexextract($path:,"(?:(?:^|\\)[^\\]*){4}")
NotNull
Posts: 5461
Joined: Wed May 24, 2017 9:22 pm

Re: List a part of path

Post by NotNull »

Was about to post a similar answer (addcolumn:A A-label:3-deep A:=REGEX_EXTRACT($path:,"^.+?\\.+?\\.+?\\") ...
But the main reason I'm posting is: why does the following not produce the same results?

Code: Select all

addcolumn:A   A-label:3-deep   A:=REGEX_EXTRACT($path:,"^(.+?\\){3}")

BTW: If only interested in the "bbbbb" part:

Code: Select all

addcolumn:A   A-label:3-deep   A:=ELEMENT($path:,"\",3)
void
Developer
Posts: 16770
Joined: Fri Oct 16, 2009 11:31 pm

Re: List a part of path

Post by void »

REGEXEXTRACT() is replaced with match 1 if you used a capture.
Otherwise, REGEXEXTRACT() is replaced with match 0.

This is similar to Google's Sheets REGEXEXTRACT().
Except, Everything does not support array objects, so only the first capture is returned.

Use (?: ... ) to avoid capturing text.



Another method:
addcolumn:a a:=pathcombine(pathcombine(element($path:,"\",1),element($path:,"\",2)),element($path:,"\",3))
NotNull
Posts: 5461
Joined: Wed May 24, 2017 9:22 pm

Re: List a part of path

Post by NotNull »

OK .. got it.
Thanks!
sk2107
Posts: 326
Joined: Sun Aug 07, 2022 8:48 pm

Re: List a part of path

Post by sk2107 »

Thanks a lot.

Best regards
NotNull
Posts: 5461
Joined: Wed May 24, 2017 9:22 pm

Re: List a part of path

Post by NotNull »

NotNull wrote: Sat Dec 09, 2023 11:48 pmOK .. got it.
On second thought ....
This will also give unexpected results with things like A:=REGEX_EXTRACT($path:,"gr(a|e)y"), which is not a capture group.
(It will only report the a or e in gray/grey).

Something to be aware of.


EDIT:
... and found a workaround :
Enclose the entire regex in an extra pair of (). That forces Everything to view the first encountered "(" to be seen as the start of the first capture group :D

Code: Select all

A:=REGEX_EXTRACT($path:,"(gr(a|e)y)")
A:=REGEX_EXTRACT($path:,"^((.+?\\){3})")
void
Developer
Posts: 16770
Joined: Fri Oct 16, 2009 11:31 pm

Re: List a part of path

Post by void »

(a|e) is a capture group.

Use (?:a|e) to avoid capturing.

Google sheets will also capture a or e with the pattern: gr(a|e)y
NotNull
Posts: 5461
Joined: Wed May 24, 2017 9:22 pm

Re: List a part of path

Post by NotNull »

void wrote: Sun Dec 10, 2023 12:13 am (a|e) is a capture group.
:shock: It is indeed! (according to regex101). I considered it to be a character class of sorts, like [ae]

(see my edit above for a workaround for these capture groups)
sk2107
Posts: 326
Joined: Sun Aug 07, 2022 8:48 pm

Re: List a part of path

Post by sk2107 »

addcolumn:a a:=regexextract($path:,"(?:(?:^|\\)[^\\]*){3}")
addcolumn:a a:=regexextract($path:,"(?:(?:^|\\)[^\\]*){2}")
addcolumn:a a:=regexextract($path:,"(?:(?:^|\\)[^\\]*){4}")
is working fine, but I have an additional question that if I can define it as filter without creating a new column with a variable level.

Thank you
void
Developer
Posts: 16770
Joined: Fri Oct 16, 2009 11:31 pm

Re: List a part of path

Post by void »

Consider the following filter:
  • From the Search menu, click Add to filters....
  • Change the Name to: First Path Parts
  • Change the Search to:

    Code: Select all

    addcolumn:a a-label:="First $param: path parts" a:=regexextract($path:,"(?:(?:^|\\)[^\\]*){$param:}") 
    
  • Change the Macro to: fpp
Now you only need to include the following in your search:
fpp:3
sk2107
Posts: 326
Joined: Sun Aug 07, 2022 8:48 pm

Re: List a part of path

Post by sk2107 »

Great.

Thanks a lot

Best regards
sk2107
Posts: 326
Joined: Sun Aug 07, 2022 8:48 pm

Re: List a part of path

Post by sk2107 »

Hello,
can I get the values in reverse? like having the last 3 parts of the path instead of the first 3.


Thank you.
void
Developer
Posts: 16770
Joined: Fri Oct 16, 2009 11:31 pm

Re: List a part of path

Post by void »

Consider the following filter:
  • From the Search menu, click Add to filters....
  • Change the Name to: Last Path Parts
  • Change the Search to:

    Code: Select all

    addcolumn:a a-label:="Last $param: path parts" a:=regexextract($path:,"(([^\\]*(\\|$)){$param:})$")
    
  • Change the Macro to: lpp
Now you only need to include the following in your search:
lpp:3
Last edited by void on Tue Jul 30, 2024 12:33 pm, edited 1 time in total.
Reason: updated old search: addcolumn:a a-label:="Last $param: path parts" a:=regexextract($path:,"(?:[^\\]*(\\|$)){$param:}$")
sk2107
Posts: 326
Joined: Sun Aug 07, 2022 8:48 pm

Re: List a part of path

Post by sk2107 »

Thank you.

One more question please; how can I use this in Advanced Move To Folder, because I need to move files to folders with new path and the last 3 parts.

f:\aaa\bbb\ccc\ddd\eee\fff\ggg\hh\file1.txt -------> f:\newfolder\ggg\hh\\file1.txt

in order to reduce path length as possible

Best Regards
void
Developer
Posts: 16770
Joined: Fri Oct 16, 2009 11:31 pm

Re: List a part of path

Post by void »

Check Regular Expressions.
Old format: ^.*\\([^\\]*)\\([^\\]*)\\([^\\]*)$
New format: f:\newfolder:\\newfolder\\\1\\\2\\\3
sk2107
Posts: 326
Joined: Sun Aug 07, 2022 8:48 pm

Re: List a part of path

Post by sk2107 »

Great. thank you so much.

Best Regards
klark1kent
Posts: 17
Joined: Thu Aug 11, 2022 1:26 am

Re: List a part of path

Post by klark1kent »

Awesome responses from Void As always, I have this working for a single column, but based on your guidance you gave 3 options for 2 levels deep, 3 levels deep, 4 levels deep... etc...

Let's say I wanted to see exactly that, 2, 3, and 4 levels deep in adjacent columns. First 2 Path Parts | First 3 Path Parts | First 4 Path Parts

I'd need to create 3 Custom Columns correct? Essentially 3 new filters, 3 custom columns, include the macros in search like fpp:2 fpp:3 fpp:4?

Or is there a simpler way to do this, and/or, is it even possible?

The reason I ask you this in particular, in case you are interested, which given you make this tool I'd assume this is up your alley. I've implemted the Folder Structure as represented in this website, and it'd be super beneficial to see those 3 broken out given the hierarchy naturally follows a 3 level deep structure.

https://johnnydecimal.com/
NotNull
Posts: 5461
Joined: Wed May 24, 2017 9:22 pm

Re: List a part of path

Post by NotNull »

Does the following search query help?
The 3 path components are in the Regular Expression Match 1 .. 3 columns.

Code: Select all

regex:"^.+?\\.+?\\(.+?)\\(.+?)\\(.+?)\\.*$"    addcolumns:regmatch1;regmatch2;regmatch3
klark1kent
Posts: 17
Joined: Thu Aug 11, 2022 1:26 am

Re: List a part of path

Post by klark1kent »

NotNull wrote: Tue Dec 26, 2023 9:16 pm Does the following search query help?
The 3 path components are in the Regular Expression Match 1 .. 3 columns.

Code: Select all

regex:"^.+?\\.+?\\(.+?)\\(.+?)\\(.+?)\\.*$"    addcolumns:regmatch1;regmatch2;regmatch3
Almost, that regex takes this: "P:\90~99_Reference\99_Standards & Ontologies\99.01_Metadata Standards\IPTC\"
And Gives me this in columns 1-3: 99_Standards & Ontologies | 99.01_Metadata Standards | IPTC

What I need is:

90~99_Reference | 99_Standards & Ontologies | 99.01_Metadata Standards

Looking at the regex though, I think I can modify it without extra help. It looked more complicated than it is.

EDIT:SOLVED
regex:"^.+?\\(.+?)\\(.+?)\\(.+?)\\(.+?)\\.*$" addcolumns:regmatch1;regmatch2;regmatch3
Post Reply