How To: Auto Provision Folders in OneDrive via Power Automate

Published by Jon

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

  1. 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.
  2. 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.
    1. 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.
  3. Zip up the folder or folder hierarchy, and upload that zip file to the root of your OneDrive.

Create the Flow and Extract Archive

  1. Create a new Flow, or navigate to your existing Flow.
  2. 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.

  1. Initialize a variable at the beginning of your Flow and call it DocumentID.
  2. Use the “Find Files in Folder by Path” action to search for documents with the specific name or file type that you used.
  3. Add a loop to the Flow and pass in the body of the previous action.
  4. Inside the loop, set the DocumentID variable to be the ID of the document from the OneDrive response.
  5. Add a “Delete File” from OneDrive inside the loop, and pass in the DocumentID variable.

Summary

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:


0 Comments

Leave a Reply

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