List a part of path
List a part of path
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
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
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}")
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
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?
BTW: If only interested in the "bbbbb" part:
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
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))
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
OK .. got it.
Thanks!
Thanks!
Re: List a part of path
Thanks a lot.
Best regards
Best regards
Re: List a part of path
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
Code: Select all
A:=REGEX_EXTRACT($path:,"(gr(a|e)y)")
A:=REGEX_EXTRACT($path:,"^((.+?\\){3})")
Re: List a part of path
(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
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
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.addcolumn:a a:=regexextract($path:,"(?:(?:^|\\)[^\\]*){3}")
addcolumn:a a:=regexextract($path:,"(?:(?:^|\\)[^\\]*){2}")
addcolumn:a a:=regexextract($path:,"(?:(?:^|\\)[^\\]*){4}")
Thank you
Re: List a part of path
Consider the following filter:
fpp:3
- 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
fpp:3
Re: List a part of path
Great.
Thanks a lot
Best regards
Thanks a lot
Best regards
Re: List a part of path
Hello,
can I get the values in reverse? like having the last 3 parts of the path instead of the first 3.
Thank you.
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
Consider the following filter:
lpp:3
- 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
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:}$")
Reason: updated old search: addcolumn:a a-label:="Last $param: path parts" a:=regexextract($path:,"(?:[^\\]*(\\|$)){$param:}$")
Re: List a part of path
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
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
Check Regular Expressions.
Old format: ^.*\\([^\\]*)\\([^\\]*)\\([^\\]*)$
New format: f:\newfolder:\\newfolder\\\1\\\2\\\3
Old format: ^.*\\([^\\]*)\\([^\\]*)\\([^\\]*)$
New format: f:\newfolder:\\newfolder\\\1\\\2\\\3
Re: List a part of path
Great. thank you so much.
Best Regards
Best Regards
-
- Posts: 17
- Joined: Thu Aug 11, 2022 1:26 am
Re: List a part of path
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/
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
Does the following search query help?
The 3 path components are in the Regular Expression Match 1 .. 3 columns.
The 3 path components are in the Regular Expression Match 1 .. 3 columns.
Code: Select all
regex:"^.+?\\.+?\\(.+?)\\(.+?)\\(.+?)\\.*$" addcolumns:regmatch1;regmatch2;regmatch3
-
- Posts: 17
- Joined: Thu Aug 11, 2022 1:26 am
Re: List a part of path
Almost, that regex takes this: "P:\90~99_Reference\99_Standards & Ontologies\99.01_Metadata Standards\IPTC\"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
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