0

I need a list of all folders including all their subfolders. The default "Get Folder" action in Power Automate gives me only the first level of subfolders but not the complete structure.

How do I retrieve the complete (sub-)folder structure and save it to a CSV file?

1 Answer 1

1

This may not be exactly what you're looking for, but it might be enough to point you in the right direction.

You can use the Send an HTTP request to SharePoint action to get all the folders in a list or library. Set these property values:

Uri: _api/Web/Lists/GetByTitle('[List Name]')/Items?$select=*,FileDirRef&$filter=FSObjType eq 1

Headers: { "Accept": "application/json;odata=nometadata" }

Replace [List Name] with the name of your list or library.

The FileDirRef field in the select is the server relative URL for the folder. The FSObjType eq 1 filter tell SharePoint you only want folders.

Send an HTTP request to SharePoint action

You can then use a Select action to extract the information you want from the response from the Send an HTTP request to SharePoint action.

Use the following expressions:

From: body('Send_an_HTTP_request_to_SharePoint')['value']

Map - Title: item()['Title']

Map - ServerRelativeUrl: item()['FileDirRef']

Select action

The output from the Select action should be an array that looks something like the JSON you see below. You could use this information to populate the CSV file.

[
    {
        "Title": "Folder 1",
        "ServerRelativeUrl": "/sites/demo3/Lists/Folder Test"
    },
    {
        "Title": "Folder 2",
        "ServerRelativeUrl": "/sites/demo3/Lists/Folder Test"
    },
    {
        "Title": "Folder 11",
        "ServerRelativeUrl": "/sites/demo3/Lists/Folder Test/Folder 1"
    },
    {
        "Title": "Folder 12",
        "ServerRelativeUrl": "/sites/demo3/Lists/Folder Test/Folder 1"
    },
    {
        "Title": "Folder 121",
        "ServerRelativeUrl": "/sites/demo3/Lists/Folder Test/Folder 1/Folder 12"
    }
]

I hope this helps.

4
  • This looks great! But now it throws an error and stops the Flow: "A potentially dangerous Request.Path value was detected from the client (*)."
    – Der_Fab
    Commented Mar 4, 2022 at 6:53
  • I assume you're getting that error from the Send an HTTP request to SharePoint action. If so, what value are you using for Uri an Headers? It could be that one of them is malformed. Commented Mar 4, 2022 at 10:10
  • I used your code: _api/Web/Lists/GetByTitle('Dokumente')/Items$select=*,FileDirRef&$filter=FSObjType eq 1 where 'Dokumente' is the library name.
    – Der_Fab
    Commented Mar 7, 2022 at 6:40
  • Sorry, my answer missed the ? between /Items and $select. The full URL should be _api/Web/Lists/GetByTitle('Dokumente')/Items?$select=*,FileDirRef&$filter=FSObjType eq 1. I updated the answer accordingly. Commented Mar 7, 2022 at 11:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.