Let's POWER Automate

From no-code to low-code

Menu
  • Expressions
  • Filters
  • General
  • Triggers
  • Application specific solutions
    • Dataverse
    • Excel
    • Forms
    • Planner
    • Outlook
    • SharePoint
    • Teams
  • Resources
  • Get help with flow
Menu

How to get files from specific SharePoint folders in Power Automate

Posted on September 22, 2021September 26, 2021 by Tom

“I have a SharePoint library with multiple parent folders, each with the same folder inside, how can I get all the files in these subfolders in a single Power Automate flow?”


The standard Power Automate action ‘Get files (properties only)’ allows you to limit the entries to a folder. But it’s just one folder. That’s fine in most situations, but what if you need to search in multiple folders? If your folder structure is more complex, e.g. multiple folders, each with their own ‘Draft’ subfolder? And you want all the documents from that subfolder?

Power Automate files SharePoint folders

The ‘Get files…’ action itself won’t help you in such situation. What you’ll need is to use a Filter Query.

Check the file path

One of the available file properties is the path to the file. If you used that in the Filter Query, you could search only for files that contain the specific folder in their path.

Unfortunately, you can’t use the ‘{FullPath}’ property in the Filter Query. But as already explained in the post on filtering by file name, you can use a similar path. The server relative path represented by the property with internal name ‘FileRef’.

Combine it with the substringof(…) filter in the Filter Query, and check if the path contains the specific folder, e.g.

substringof('Draft', FileRef)

Such ‘Get files…’ action will return only files with ‘Draft’ in their path = files in the ‘Draft’ folder.

Skip the folders themselves

Since the ‘Get files…’ will return everything with the folder name in the path, it’ll return the folder(s) too. Processing a folder could cause errors in your flow as it’s not an actual file. It doesn’t have content nor properties, and it’s better to ignore them. Do that by using the other “hidden” file property: FileLeafRef – the file name with extension. As the folder doesn’t have any extension, it’ll contain just the folder name.

The file path must contain ‘Draft’ (the folder name), but at the same time the file can’t be called ‘Draft’. Add the second filter to the Filter Query with the AND operator.

substringof('Draft', FileRef) and FileLeafRef ne 'Draft'
Power Automate files SharePoint folders

The result will be only the files in the ‘Draft’ folders.

Summary

Even if Power Automate doesn’t allow you to get files from multiple SharePoint folders directly, you can still filter them out with a Filter Query. A Filter Query that looks simple, but there’re some advanced concepts behind. There’s the substring(…) filter, where I often enter the parameters in the wrong order. The FileRef and FileLeafRef properties, not shown anywhere in the file properties, but necessary to work with files. And the combination of multiple filters in a single Filter Query.


Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to resources like a SharePoint Filter Query cheat sheet or Date expressions cheat sheet.

Zero spam, unsubscribe anytime.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Do you know what to do, but not how to do it?

Get The Ultimate Power Automate expressions cheat sheet and translate your thoughts into flows with ease!


NEW! Master the HTTP requests to SharePoint with a new cheat sheet!

Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to resources like a SharePoint Filter Query cheat sheet or Date expressions cheat sheet.

Zero spam, unsubscribe anytime.

Hello and welcome!

My name is Tom and I'm a business process automation consultant and Microsoft MVP living in the Czech Republic. I’ve been working with Microsoft technologies for almost 10 years, currently using mainly Power Automate, SharePoint, Teams, and the other M365 tools.

I believe that everyone can automate part of their work with the Power Automate platform. You can achieve a lot by "clicking" the flows in the designer, but you can achieve much more if you add a bit of coding knowledge. And that's what this blog is about.

To make the step from no-code Power Automate flows to low-code flows: using basic coding knowledge to build more complex yet more efficient flows to automate more of your daily tasks.

  • Use Power Automate to forward Outlook events upon registrationJanuary 29, 2023
  • Why the condition is false for the same numbers (Power Automate)January 25, 2023
  • How to forward event invitation to other calendar (Power Automate)January 22, 2023
  • Run ‘For selected item’ flow from non-default environment (Power Automate)January 18, 2023
  • Hide button in SharePoint list after Power Automate flow startedJanuary 15, 2023

Power Automate blogs worth visiting

Damien Bird
Dennis (Expiscornovus)
Paul Murana

©2023 Let's POWER Automate | Theme by SuperbThemes