When comparing the integration points between Power Automate and either OneDrive or SharePoint, you start to notice that the SharePoint actions are much more robust when working with folder structures. Power Automate doesn’t allow you to auto provision folders in OneDrive, and many of the file actions do not work with folders.
There is a workaround which I will detail below. This workaround is thanks to the fact that Power Automate has a OneDrive action called “Extract Archive to Folder” that will essentially auto provision a brand new folder hierarchy. It’s a cool way to workaround a piece of functionality that feels like should be there natively.
Create the Folder Hierarchy
- In the File Explorer on your desktop, create a folder or folder hierarchy representing the folders you want Power Automate to provision each time you run it.
- Important: Power Automate will not provision folders without any files in them, so for every folder you create you need to put an office document (Word, Excel, PPT etc.) in there of some kind.
- Tip: Name them all the same thing and keep them the same file type, so that when you delete the files in Power Automate later you don’t have to search for different file types.
- Zip up the folder or folder hierarchy, and upload that zip file to the root of your OneDrive.
Create the Flow and Extract Archive
- Create a new Flow, or navigate to your existing Flow.
- Add an action called Extract Archive to Folder from the OneDrive connector and pass in the path of your zipped up file. In the image below, mine is called Client1.
Delete Uploaded Documents
Now we need to delete the blank documents that were created as part of the initial folder structure.
- Initialize a variable at the beginning of your Flow and call it DocumentID.
- Use the “Find Files in Folder by Path” action to search for documents with the specific name or file type that you used.
- Add a loop to the Flow and pass in the body of the previous action.
- Inside the loop, set the DocumentID variable to be the ID of the document from the OneDrive response.
- Add a “Delete File” from OneDrive inside the loop, and pass in the DocumentID variable.
Auto Provision Folders in OneDrive can be painful, but this method can save a lot of time manually creating a templated folder structure. For more reading see the Microsoft documentation below:
- Extract Archive to Folder
- “Find Files in Folder by Path” Documentation