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

Community site session details

Session Id : jTgfscPw9KkiT7vJKE4Z/J
Power Automate - Building Flows
Answered

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

Like (0) ShareShare
ReportReport
Posted on 8 Mar 2021 16:22:12 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

I have the same question (0)
  • eliotcole Profile Picture
    4,280 Moderator on 05 Dec 2023 at 19:29:01
    Re: How to get a flat listing of all files with path for all subfolders

    Oh totally, sorry, I wasn't dismissing your amazing efforts! 🏆

     

    I ended up using multcloud, who it would appear are running a permanent sale (hi, Sports Direct want their schtick back!) on lifetime licences. Their integrations made it really easy for me to get things done regarding what I needed to do. But I'm not advertising them ... just saying that they helped me over the line after I hyperfocused on trying every which way else. 😅

     

    FWIW, though, for the future, Logic Apps costs run into the micropennies, and are (mostly) charged per action on the consumption plan. This can often vastly undercut doing similar work in Power Automate, even if you bring in the other products that I mentioned.

     

    But ... again ... that's not dismissing you ... just putting it there for future thinks.

  • martinav Profile Picture
    3,340 on 05 Dec 2023 at 19:17:35
    Re: How to get a flat listing of all files with path for all subfolders

    @eliotcole ,

     

    Yea, I am doing this for my company, but its too small to allow purchasing of other tools.  Thats why I'm actually doing what I'm doing, because we cannot afford a fully developed MRP/ERP system.  Plus other things.  But, what i'm doing is specific for our company so it works very well.

  • eliotcole Profile Picture
    4,280 Moderator on 05 Dec 2023 at 19:02:22
    Re: How to get a flat listing of all files with path for all subfolders

    There may be a way around this using separate flows and then kicking them off like you were using functions in javascript or something.

     

    It would still take a long time, but I affected something similar to get a HUGE amount of files from a Google Drive last year! Still had to bend around large files, but I got very close I think.

     

    Again, though ... hugely inefficient. There's probably better tools out there. Also, if you were to be doing something like this for work, I'd advise perhaps using Logic Apps in conjunction with Data Factory, perhaps. 👍

  • DAHPower Profile Picture
    on 05 Dec 2023 at 18:25:35
    Re: How to get a flat listing of all files with path for all subfolders

    @martinav 

    Ah my bad. I got it mixed up from the thread, your original post mentions the file system.

  • martinav Profile Picture
    3,340 on 05 Dec 2023 at 17:51:00
    Re: How to get a flat listing of all files with path for all subfolders

    @DAHPower ,

     

    While true for Sharepoint, the initial request, which was perhaps not clear, was for File System actions, which apply to shared folder lists.

  • DAHPower Profile Picture
    on 05 Dec 2023 at 12:16:13
    Re: How to get a flat listing of all files with path for all subfolders

    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".

     

  • ResearchCaptain Profile Picture
    4 on 21 Jul 2023 at 15:15:57
    Re: How to get a flat listing of all files with path for all subfolders

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

  • obadiahjohnson Profile Picture
    106 on 31 Mar 2023 at 15:38:15
    Re: How to get a flat listing of all files with path for all subfolders

    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"
            ]
        }
    }

     

  • DH-27020923-0 Profile Picture
    on 31 Mar 2023 at 08:24:06
    Re: How to get a flat listing of all files with path for all subfolders

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

  • obadiahjohnson Profile Picture
    106 on 10 Mar 2023 at 17:28:34
    Re: How to get a flat listing of all files with path for all subfolders

    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.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

MS.Ragavendar – Community Spotlight

We are honored to recognize Ragavendar Swaminatha Subramanian as our September…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 736 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 396 Moderator

#3
Power Apps 1919 Profile Picture

Power Apps 1919 339

Last 30 days Overall leaderboard