So often I hear complaints about SharePoint actions in flow not working. In this post I will look at the complication when you try to get all files in a folder in SharePoint.
But actually you only really need one action. Just make sure that you use the right action. Get files may look like the right action, but the Send an HTTP request to SharePoint can do so many things and it is easy to configure, if you know how to.
Get all files from a folder
Table of Contents
Today I tried to get all files in a folder in SharePoint library. At first you might try to do this using the following flow with a Get files (properties only) action.
You might even have figured out that the {FullPath} field contains the path to the folder holding the files that you are interested in. But before you know you will have spend hours trying to make this work.
The underlying API uses a REST API call and the fields with the { … } simply give bad request error messages.
Send an HTTP request to SharePoint
As so many times the Send an HTTP request to SharePoint will give the easy solution. The SharePoint REST API documentation will quite quickly give you the right syntax.
The REST API url that I’ve built up is:
https://pieterveenstramvp.sharepoint.com/_api/web/GetFolderByServerRelativeUrl('/Shared%20Documents/testfolder')/files
Did anybody say that REST API calls are complicated?
See also
Today 19 March 2020, I noticed an update to the Get Files action, see my post about these changes helping you filter by folder in the get files action.
Hi Pieter – there is a native action that does this, its called ‘List Folder’
Hi Ariel,
I am aware of that action. It is however more complicated to make it work when you include subsite, document libraries with spaces and folder and sub folder. With this HTTP request action it’s just a simple URL that needs to be configured.
Also the Send an HTTP request to SharePoint is so much easier to configure when you want flows that can be moved between environments.
One of my clients (a citizen developer) battled for 2 hours with the List Folder action. The action in the post is a very easy to configure REST API call.
OK…so how do you [Apply to each] through that object payload to copy each file to a new folder (document set)? I did a [Parse JSON] but it is still an object and [Apply to each] wants an array. And [List Folder] is a PITA.
Do you have an example of the json that you get?
You might have query in the json as described in the post below.
https://sharepains.com/2019/09/16/query-json-in-microsoft-flow/
Then you can get to your data. If you need help then please send the json that you are receiving.
I did manage to get that info by doing a Parse JSon…then a Apply to Each…and I put an array variable in that and it did cycle through the files so I could copy…thanks for putting me on the right path!
From what I can tell, the /files command only gets .. files.
It does not return any subfolders, or document sets, so it’s incomplete as a replacement.
Have you tried /folders? that gives you all the folders.
hey peter, thanks for this. it seems to work but im not getting any content on the response its just blank. Am i Doing something wrong
Hi Christopher,
Are you getting any errors back? When you run the flow what does the Send an HTTP Request return? any errors?
Can you post the url? Feel free to use the chat on this site.
can we save these files to local PC easily ? i dont mean to my onedrive but just some folder in C Drive
Not with flow. Use a local PowerShell instead to read the files and download the files. I would look at pnp PowerShell
can we save these files to local PC easily ? i dont mean to my onedrive but just some folder in C Drive
HI Pieter. Great stuff, thank you.
Can you help further? These HTTP calls don’t seem to read into subfolders, correct?
I am trying to move a folder, with files and subfolders, from a SharePoint doclib to a OneDrive folder.
It’s looking like I have to build a loop to traverse the tree, right? I thought “Get Files (properties only)” or “List Folder” would work for me, but having no luck. The Get Files consistently returns nothing [], with no errors and List Folder doesn’t recurse down into sub folders. The library is quite large (140,000 items) in case that matters. Thoughts?
Thank you,
Gerry
Hi Gerry, i would have a look into the SharePoint migration tool or maybe tools like ShareGate to do that.
Upon further testing, the “Get Files” fails when I set it to “yes” to read subfolders. It returns nothing in that case. 🙁