Power Query How to list folder names only NOT files

Joyner

Well-known Member
Joined
Nov 15, 2005
Messages
1,202
Hello, I am fairly new to Power Query and have searched but can't find a solution - every thing I find is related to listing files, not folders. Is it possible for power query to just list folder names from a path? I can list all files with the path and extract the folder name but removing the duplicates with the voluminous files is taking way too long for some reasons, so if I can just list the folder names instead of all files should be much faster.

Thank You
 
just for fun I added one line:
Code:
[SIZE=1]Level = Table.AddColumn(#"Sorted Rows", "Level", each List.Count(Text.PositionOf([Folder Path],"\", Occurrence.All)))[/SIZE]
 
Upvote 0

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Hello Bill and Sandy, and thank you again. I am trying to run the code, maybe I'm doing the FPath part wrong, because it doesn't seem to be picking the path up. Is the FPath simply a Defined Name on any sheet, or does it need to be a table formatted a certain way? Thanks
 
Upvote 0
look at

screenshot-9.png
 
Upvote 0
Sorry for the late response I have been tied up and trying the solutions. Thanks to everyone for the help.
 
Upvote 0
just for fun I added one line:
Code:
[SIZE=1]Level = Table.AddColumn(#"Sorted Rows", "Level", each List.Count(Text.PositionOf([Folder Path],"\", Occurrence.All)))[/SIZE]

Sandy, I wasn't sure how this got added and what it does.
 
Upvote 0
As I promised (but it is draft only).
Code:
let    fxNewPaths = (t as table, i as number) =>
        let
            iActual = "L" & Text.From(i),
            iNext = "L" & Text.From(i+1),
            AddCol1 = Table.AddColumn(t, "Lx", each try Table.SelectColumns(Table.AddColumn(Table.SelectRows(Folder.Contents(Record.Field(_, iActual)), each [Content] is table)[[Folder Path],[Name]], iNext, each [Folder Path] & [Name]), {iNext}) otherwise null),
            Expand = Table.ExpandTableColumn(AddCol1, "Lx", {iNext})
        in
            Expand,


    FPath = Excel.CurrentWorkbook(){[Name="FPath"]}[Content]{0}[Column1],
    FirstRow = Table.FromColumns({{FPath}}, {"L0"}),
    LiG = List.Generate(() => [FR = FirstRow, i = 0],
                    each List.NonNullCount( Table.Column([FR], "L"& Text.From([i]))) <> 0,
                    each [FR = fxNewPaths([FR], [i]), i = [i]+1],
                    each [FR]),
    TBL = List.Last(LiG),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(TBL, {}, "Attribute", "Folder Path"),
    #"Removed Columns" = Table.RemoveColumns(#"Unpivoted Columns",{"Attribute"}),
    #"Removed Duplicates" = Table.Distinct(#"Removed Columns"),
    #"Sorted Rows" = Table.Sort(#"Removed Duplicates",{{"Folder Path", Order.Ascending}})
in
    #"Sorted Rows"

FPath is (as in my previous post) a named cell in the workbook that contains the path to the start folder.

Thank you Bill, I have gotten this to work, but many times it still seems to take a long time to run. Maybe it's just my computer.
 
Upvote 0
Does anyone know, if you can somehow hyperlink the path without VBA. I have searched and it seems that with Excel (Not Power BI) that this is not possible. Thank You.
 
Upvote 0
add prefix: HYPERLINK("
then add suffix: ")
then add prefix: =
load to the sheet
then replace = with =

edit:

but after refresh you'll need repeat last line
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,275
Messages
6,171,123
Members
452,381
Latest member
Nova88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top