Dynamically Create Nested Folders Using The New 'Create New Folder' Action Of Microsoft Flow

In this article, you will learn how to dynamically create nested folders using the new 'create new folder' action of Microsoft Flow.

Introduction

 
A new action called ‘Create new folder’ was released in MS Flow in July, 2019. Before this action, there was no direct way of creating a new folder. There were workarounds which involved many repetitive steps and the solutions are not scalable. With this new action, we can easily create folders and nested subfolders with a simple flow action.
 

Creating Nested Folders

 
Let us take a scenario where we maintain a list of products and their supporting documents in a folder structure. So, when a new product is added (i.e., an item in a list is created), we would like to create a predefined folder structure (in Document library) and map the folder path to the product (update list item). In this article, I will explain how to create an MS Flow which would perform the below series of actions,
 
  1. User creates a new item in the Products list
  2. MS Flow is triggered to automatically created the following folder structure

    <Product Name> -> Sales
    <Product Name> -> Technical Specs


  3. And the path to the product document’s folder is updated for the product.
For this example, I am using a list called Products with 2 columns, Title and a Documents column of type Hyperlink. The folder structure will be created in the default Documents library of the site collection.
 

Building MS Flow for creating the Folder Structure

  1. Create a new Flow with by selecting the trigger – ‘When an item is created’. Choose the appropriate Site Address and List Name based on your environment.


  2. Click on Add step and search for create folder. You will a new action called ‘Create new folder’ which was added recently. Select this action.


  3. Configure the properties of this step,

    a. Site Address - URL of your site collection
    b. List or Library - Choose the list or library where you want the folder to be created
    c. Folder Path - You can use the Dynamic Content to name the folders based on variables or properties from your previous steps. In this case, I use the ‘Title’ property of the ‘When an item is created’ step. This property accepts a path (like folder1/folder2/folder3) and it recursively creates the nested folders if they are not available.


  4. Add another ‘Create new folder’ action step and configure the values as shown below. In this example shown. You can either add multiple steps for creating more folders. Or use a foreach action and add the ‘Create new folder’ step.


    In this example, as mentioned in the Folder Path, the first action creates 2 folders (i.e., a folder at the root with the name as list item title, and a subfolder called Sales). The second action creates only one folder called Technical Specs, as the root folder is already present.

  5. The last step shows how we can use the metadata of the newly created folder. We can add a step to ‘Update item’ and use the dynamic properties of the ‘Create new folder’ step to update the URL in the SharePoint list item.

With the above steps configured, we can now save the MS Flow, and now whenever we create a new item in the list, a folder structure is created based on the title of the products list item.
 

Summary

 
This article shows a simple use case of how we can use the ‘Create new folder’ action to create nested folders by dynamically choosing the folder names. While Document Sets are also used in a few scenarios, some users prefer to use a simple nested folder structure approach which is easy and simple to use.
 
The new MS flow action to create a new folder makes it easy to create such folder structures and nested folders.