Page 1 of 1

List a part of path

Posted: Sat Dec 09, 2023 11:11 pm
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

Re: List a part of path

Posted: Sat Dec 09, 2023 11:30 pm
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}")

Re: List a part of path

Posted: Sat Dec 09, 2023 11:38 pm
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)

Re: List a part of path

Posted: Sat Dec 09, 2023 11:44 pm
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))

Re: List a part of path

Posted: Sat Dec 09, 2023 11:48 pm
by NotNull
OK .. got it.
Thanks!

Re: List a part of path

Posted: Sat Dec 09, 2023 11:49 pm
by sk2107
Thanks a lot.

Best regards

Re: List a part of path

Posted: Sun Dec 10, 2023 12:08 am
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})")

Re: List a part of path

Posted: Sun Dec 10, 2023 12:13 am
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

Re: List a part of path

Posted: Sun Dec 10, 2023 12:29 am
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)

Re: List a part of path

Posted: Tue Dec 12, 2023 10:28 am
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

Re: List a part of path

Posted: Tue Dec 12, 2023 10:53 am
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

Re: List a part of path

Posted: Tue Dec 12, 2023 11:26 am
by sk2107
Great.

Thanks a lot

Best regards

Re: List a part of path

Posted: Sun Dec 24, 2023 10:51 am
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.

Re: List a part of path

Posted: Sun Dec 24, 2023 11:04 am
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

Re: List a part of path

Posted: Sun Dec 24, 2023 11:21 am
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

Re: List a part of path

Posted: Sun Dec 24, 2023 11:45 am
by void
Check Regular Expressions.
Old format: ^.*\\([^\\]*)\\([^\\]*)\\([^\\]*)$
New format: f:\newfolder:\\newfolder\\\1\\\2\\\3

Re: List a part of path

Posted: Sun Dec 24, 2023 12:25 pm
by sk2107
Great. thank you so much.

Best Regards

Re: List a part of path

Posted: Tue Dec 26, 2023 9:07 pm
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/

Re: List a part of path

Posted: Tue Dec 26, 2023 9:16 pm
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

Re: List a part of path

Posted: Tue Dec 26, 2023 9:45 pm
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