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.
- The user creates a new item in the Products list.
- MS Flow is triggered to automatically create the following folder structure.
- <Product Name>: Sales
- <Product Name>: Technical Specs
- 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, a 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
- 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.
- Click on the Add step and search for Create folder. You will a new action called ‘Create new folder’ which was added recently. Select this action.
- Configure the properties of this step.
- Site Address: URL of your site collection
- List or Library: Choose the list or library where you want the folder to be created
- Folder Path: You can use 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.
- 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.
- 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 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.