web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / How to get a flat list...
Power Automate
Unanswered

How to get a flat listing of all files with path for all subfolders

(0) ShareShare
ReportReport
Posted on by 3,340

I'm looking to generate a list of full path to file for all subfolders.  I believe current "List Files In Folder" File System action only gets the top level.  Any Ideas that isnt some crazy nested loop scenario hitting all folders individually?

 

Thanks,
Rod

Categories:
I have the same question (0)
  • Pstork1 Profile Picture
    68,697 Most Valuable Professional on at

    Unfortunately, the only way to do this would be to write the flow to query each sub folder recursively.  There is no action for the on-premises file system that uses a flat view of the files.  Everything is viewed in the context of folders.

  • annajhaveri Profile Picture
    8,531 Most Valuable Professional on at

    @martinav  you can use Get Items to get all files with all subfolders, configure the Get Items as shown in screenshot below. In List Name, specify Document library name by select Custom Value from dropdown, and set Include Nested Items to yes.

    annajhaveri_1-1615221217509.png

    Also its a good idea to specify a filter query or top count to get only those items you need to improve performance of the flow.

     

     

  • Pstork1 Profile Picture
    68,697 Most Valuable Professional on at

    @annajhaveri he's trying to get the list from the File System, not SharePoint.  The same option doesn't exist in the File System connector actions.

  • Verified answer
    martinav Profile Picture
    3,340 on at

    Yea, unfortunately, I ended up having to do what I didn't want too.  Since everything is two layers deep, and consistent, it makes it a little simpler than if it were a mix of different levels.  But, it still takes forever to run it.  Apply to each is horribly slow.  Always was.  It seems wrong, because a recursive list of a folder with its entire sub structure only takes seconds in the old world.

     

    Command line:

    ls -lR | FlatList.txt

     

    Flow:

     

    martinav_0-1615233430935.png

     

  • annajhaveri Profile Picture
    8,531 Most Valuable Professional on at

    @Pstork1 thanks for pointing out, i overlooked the file system from his question.

  • obadiahjohnson Profile Picture
    106 on at

    I've worked out a way to do this. 

    You run the List Folder and add that body in to an Array Variable. 

    You then use Parse JSON to extract the data and pump those variables into another list folder.

    You then have a condition on 'Is Folder' property and handle your files and folders as you need. 

    Basically, it's a 'flat' version of a loop but it's no longer limited by the nesting limit in Power Automate. I have a directory 10 subfolders deep that I'm using this on. I hope this helps, I didn't find much when researching this.

  • DH-27020923-0 Profile Picture
    on at

    Could you explain this in more detail? Im having a hard time following the steps

  • obadiahjohnson Profile Picture
    106 on at

    Sure thing. I marked each iteration of the process of a level so you can see how deep into the folder structure you're getting.

    First you  create an array for each level you want to go down into a folder structure.  Level 0 would be the root folder, level one the subfolder, level to the subfolder of that subfolder and so on.

    Array Declarations.png

    This step is where most of the work happens.

    Then you point List folder to the root folder, create a condition on whether the file in the current iteration is a folder. If Yes, use the ID of that current file in a new List Folder and append the results to the array variable corresponding to that next level.

    For my purposes I was pulling data from the file if it was not a folder (the no column).

    For your purposes you'd probably have some method of adding to a variable that tracks the list for each folder and subfolder under but the yes & no columns of the condition so you can list all the files & folders. Or you could have it write the name to a spreadsheet. Lots of options there.

    Level 0 Processing.png

    Then you use Parse JSON on your array for the next folder level to get the metadata. Then you add the Body of that parse JSON to the next loop and repeat the whole cycle over again. I got this Parse JSON from pulling the output of List folder, clicking Generate from Sample, and pasting it in there. I've pasted my parse JSON below but if, for some reason, you have different information, you can follow the same process to get a customize Parse JSON to use for your directory.

    Parse JSON & repeat.png

    This gives you minimal nesting with a linear process to chain together folder information as you go deeper into your folder structure.

    Minimized view.png

    Parse JSON I used:

     

    {
        "type""array",
        "items": {
            "type""object",
            "properties": {
                "Id": {
                    "type""string"
                },
                "Name": {
                    "type""string"
                },
                "DisplayName": {
                    "type""string"
                },
                "Path": {
                    "type""string"
                },
                "LastModified": {
                    "type""string"
                },
                "Size": {
                    "type""integer"
                },
                "IsFolder": {
                    "type""boolean"
                }
            },
            "required": [
                "Id",
                "Name",
                "DisplayName",
                "Path",
                "LastModified",
                "Size",
                "IsFolder"
            ]
        }
    }

     

  • ResearchCaptain Profile Picture
    4 on at

    Thank you so much for this! I've been searching all over for a solution that avoids excessive nesting

  • DAHPower Profile Picture
    on at

    If you want to get a flat list of a files in a Sharepoint document library or any specific folder, you can use the action "Get Files (properties only)" add the Filter Query: FSObjType eq 0. Like so: 

    DAHPower_0-1701778089510.png

    This will return an array of all files (including fullPath and Link) in the folder you specify or for the entire document library if you don't specify any folder in "Limit entries to folder".

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 538 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 405 Moderator

#3
abm abm Profile Picture

abm abm 252 Most Valuable Professional

Last 30 days Overall leaderboard