cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
martinav
Community Champion
Community Champion

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

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

1 ACCEPTED SOLUTION

Accepted Solutions
martinav
Community Champion
Community Champion

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

 

View solution in original post

15 REPLIES 15
Pstork1
Most Valuable Professional
Most Valuable Professional

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.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
annajhaveri
Most Valuable Professional
Most Valuable Professional

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

 

 

Regards,
Anna Jhaveri

If I have answered your question, please mark the post as Solved to help other users to identify the correct answer
If you like my response, please give it a Thumbs Up.
Pstork1
Most Valuable Professional
Most Valuable Professional

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



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
martinav
Community Champion
Community Champion

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
Most Valuable Professional
Most Valuable Professional

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

Regards,
Anna Jhaveri

If I have answered your question, please mark the post as Solved to help other users to identify the correct answer
If you like my response, please give it a Thumbs Up.
obadiahjohnson
Advocate III
Advocate III

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.

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

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
New Member

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

DAHPower
Frequent Visitor

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

 

@DAHPower ,

 

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

@martinav 

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

eliotcole
Super User
Super User

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

martinav
Community Champion
Community Champion

@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
Super User
Super User

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.

Helpful resources

Announcements

Check out the Copilot Studio Cookbook today!

We are excited to announce our new Copilot Cookbook Gallery in the Copilot Studio Community. We can't wait for you to share your expertise and your experience!    Join us for an amazing opportunity where you'll be one of the first to contribute to the Copilot Cookbook—your ultimate guide to mastering Microsoft Copilot. Whether you're seeking inspiration or grappling with a challenge while crafting apps, you probably already know that Copilot Cookbook is your reliable assistant, offering a wealth of tips and tricks at your fingertips--and we want you to add your expertise. What can you "cook" up?   Click this link to get started: https://aka.ms/CS_Copilot_Cookbook_Gallery   Don't miss out on this exclusive opportunity to be one of the first in the Community to share your app creation journey with Copilot. We'll be announcing a Cookbook Challenge very soon and want to make sure you one of the first "cooks" in the kitchen.   Don't miss your moment--start submitting in the Copilot Cookbook Gallery today!     Thank you,  Engagement Team

Announcing Power Apps Copilot Cookbook Gallery

We are excited to share that the all-new Copilot Cookbook Gallery for Power Apps is now available in the Power Apps Community, full of tips and tricks on how to best use Microsoft Copilot as you develop and create in Power Apps. The new Copilot Cookbook is your go-to resource when you need inspiration--or when you're stuck--and aren't sure how to best partner with Copilot while creating apps.   Whether you're looking for the best prompts or just want to know about responsible AI use, visit Copilot Cookbook for regular updates you can rely on--while also serving up some of your greatest tips and tricks for the Community. Check Out the new Copilot Cookbook for Power Apps today: Copilot Cookbook - Power Platform Community.  We can't wait to see what you "cook" up!    

Welcome to the Power Automate Community

You are now a part of a fast-growing vibrant group of peers and industry experts who are here to network, share knowledge, and even have a little fun.   Now that you are a member, you can enjoy the following resources:   Welcome to the Community   News & Announcements: The is your place to get all the latest news around community events and announcements. This is where we share with the community what is going on and how to participate.  Be sure to subscribe to this board and not miss an announcement.   Get Help with Power Automate Forums: If you're looking for support with any part of Power Automate, our forums are the place to go. From General Power Automate forums to Using Connectors, Building Flows and Using Flows.  You will find thousands of technical professionals, and Super Users with years of experience who are ready and eager to answer your questions. You now have the ability to post, reply and give "kudos" on the Power Automate community forums. Make sure you conduct a quick search before creating a new post because your question may have already been asked and answered. Galleries: The galleries are full of content and can assist you with information on creating a flow in our Webinars and Video Gallery, and the ability to share the flows you have created in the Power Automate Cookbook.  Stay connected with the Community Connections & How-To Videos from the Microsoft Community Team. Check out the awesome content being shared there today.   Power Automate Community Blog: Over the years, more than 700 Power Automate Community Blog articles have been written and published by our thriving community. Our community members have learned some excellent tips and have keen insights on the future of process automation. In the Power Automate Community Blog, you can read the latest Power Automate-related posts from our community blog authors around the world. Let us know if you'd like to become an author and contribute your own writing — everything Power Automate-related is welcome.   Community Support: Check out and learn more about Using the Community for tips & tricks. Let us know in the Community Feedback  board if you have any questions or comments about your community experience. Again, we are so excited to welcome you to the Microsoft Power Automate community family. Whether you are brand new to the world of process automation or you are a seasoned Power Automate veteran - our goal is to shape the community to be your 'go to' for support, networking, education, inspiration and encouragement as we enjoy this adventure together.     Power Automate Community Team

Hear what's next for the Power Up Program

Hear from Principal Program Manager, Dimpi Gandhi, to discover the latest enhancements to the Microsoft #PowerUpProgram, including a new accelerated video-based curriculum crafted with the expertise of Microsoft MVPs, Rory Neary and Charlie Phipps-Bennett. If you’d like to hear what’s coming next, click the link below to sign up today! https://aka.ms/PowerUp  

Tuesday Tip | How to Report Spam in Our Community

It's time for another TUESDAY TIPS, your weekly connection with the most insightful tips and tricks that empower both newcomers and veterans in the Power Platform Community! Every Tuesday, we bring you a curated selection of the finest advice, distilled from the resources and tools in the Community. Whether you’re a seasoned member or just getting started, Tuesday Tips are the perfect compass guiding you across the dynamic landscape of the Power Platform Community.   As our community family expands each week, we revisit our essential tools, tips, and tricks to ensure you’re well-versed in the community’s pulse. Keep an eye on the News & Announcements for your weekly Tuesday Tips—you never know what you may learn!   Today's Tip: How to Report Spam in Our Community We strive to maintain a professional and helpful community, and part of that effort involves keeping our platform free of spam. If you encounter a post that you believe is spam, please follow these steps to report it: Locate the Post: Find the post in question within the community.Kebab Menu: Click on the "Kebab" menu | 3 Dots, on the top right of the post.Report Inappropriate Content: Select "Report Inappropriate Content" from the menu.Submit Report: Fill out any necessary details on the form and submit your report.   Our community team will review the report and take appropriate action to ensure our community remains a valuable resource for everyone.   Thank you for helping us keep the community clean and useful!

Users online (4,845)