In this Power Automate tutorial, we will learn how to create a folder in SharePoint using Power Automate. I will also tell you how to create a folder if it does not exists using Power Automate using different ways.
The flow uses manual triggers, by using Get Files (Properties only) action, it loops through all the folders present in the SharePoint Document library, and then, if it does not exist, it creates a new folder.
To get a clear understanding of how to create a Folder in SharePoint Document Library using Power Automate flow, follow the below headings:
Create a Folder in SharePoint using Power Automate
Let us see how to create a Folder in SharePoint Document Library using Power Automate flow,
Log in to Power Automate, click +Create, then select Instant Cloud Flow -> Enter flow name -> Choose Manually trigger a flow and click the create button.
Expand the Manual trigger action and add a Text input to get the Folder name from users.
Add + new step and select Create new folder action from action triggers. Then Provide the below details:
- SiteAddress – Select the SharePoint site
- List or Library – Choose the List or Document Library
- Folder Path – By default, it creates a folder in SharePoint Document Library. Provide the Folder Path for subfolders.
Save and Run the flow, Enter the Folder Name, and select the run flow option.
Once the flow ran successfully like below:
The New folder has been created in the SharePoint document library using Power Automate flow.
This is how to create a Folder in SharePoint Document Library using Power Automate flow.
Create a SharePoint folder if not exists using Power Automate
Let us see how to create a SharePoint folder if not exists using Power Automate.
In this example, we will first get all the documents from the SharePoint Document Library using get file properties, and then we check if the folder exists; we will not create a folder; else, we will create a folder.
Example:1 (Using Create Folder action)
To achieve this, follow the below steps:
Step:1
Create an Instant cloud flow, expand the Manual trigger action, and add a Text input to get the Folder name from users.
Step:2
Select + New step and choose the Get Files (Properties only) action from the action trigger. Then Provide the details below:
- Site Address – Choose SharePoint site address
- Library Name – Choose the document library
- Filter Query – apply the below filter query code
ContentType eq 'Folder'
Step:3
Add a new step, initialize the variable, enter the variable name as isFolderExists, choose the Variable type as Boolean, and set the value as false by default.
Step:4
Now select apply to each control and select the values from dynamic content to loop through all the folders present in the SharePoint Document Library.
- Add a condition control to check if the folder exists or not, Select the dynamic content Name Values is equal to the Folder Name.
- If the Folder exists in the SharePoint Document library, then in the If yes condition, we will set the boolean value as true by using the set variable action; else, leave it blank.
- In the set variable action, In the name section, select the initialized variable from the drop-down, and in the value section, pass the value as true.
Step:5
- Now we will add a condition to check if the initialized boolean variable is equal to false.
- If yes, then we will create a Folder in Our SharePoint document library by using create a new folder action else leave it blank.
- In the create a new folder action, provide the below details:
- SiteAddress – Select the SharePoint site
- List or Library – Choose the List or Document Library
- Folder Path – By default, it creates a folder in SharePoint Document Library. Provide the Folder Path for subfolders.
Step:6
Save and Run the flow by selecting the Run flow option.
Case 1:
In the screenshot below, you can see the existing folders presented in the document library.
Here I will pass the Folder name as HRDetails and select the run flow option.
You can see our flow ran successfully and doesn’t create any folders in the SharePoint library because the folder is existing in a document library.
Case:2
In the same way, I am going to pass the Folder name as EmployeeUserManuals and select the run flow option.
You can see our flow ran successfully, and we created a new folder in the SharePoint library because the folder does not exist in a document library.
In the below screenshot, you can see that the folder has been created in the document library.
This is one way to create a SharePoint folder if not exist using Power Automate flow.
Example:2 (Using REST API)
Let us know how to create a SharePoint folder if not exist using Power Automate REST API.
To achieve this, follow the below steps:
Step:1
Create an instant cloud flow, expand the Manual trigger action, and add a Text input to get the Folder name from users.
Step:2
Select + New step and choose the Get Files (Properties only) action from the action trigger. Then Provide the details below:
- Site Address – Choose SharePoint site address
- Library Name – Choose the document library
- Filter Query – apply the below filter query code
ContentType eq 'Folder'
Step:3
Add a new step and choose select data operation in the From values, pass the dynamic content values, and in the Map the Folder Path.
Step:4
Now add a compose action to get the shared document folder path based on the index, add the below expression, and select the ok button.
body('Select')?[0]
Step:5
Then add a ‘Send an HTTP request to SharePoint’ action. Provide the SharePoint site address and set the below properties:
- Method- POST
- Uri- /_api/web/folders
- Headers-
- accept – application/json;odata=verbose
- content-type – application/json;odata=verbose
- Body-
{
"__metadata": {
"type": "SP.Folder"
},
"ServerRelativeUrl":'@{outputs('Path')}@{triggerBody()['text']}'
}
Step:6
Save and Run the flow by selecting the Run flow option.
In the screenshot below, you can see the existing folders presented in the document library.
Here I am going to pass the Folder name as ConfidentialDocumentsand select the run flow option.
You can see our flow ran successfully, and created a new folder in the SharePoint library because the folder does not exist in a document library.
In the below screenshot, you can see that the folder has been created in the document library.
This is another way to create a SharePoint folder if not exist using Power Automate REST API.
These are the two ways to create a SharePoint folder if not exist in Power Automate flow.
Example:3 (Using Filter Array action)
Let us see how to create a SharePoint folder if not exist using the Filter array action in Power Automate.
In this example, we will first get all the documents from the SharePoint Document Library using get file properties, and then we check if the folder exists by using the filter array action; If it exists we will not create a folder; else, we will create a folder.
To achieve this, follow the below steps:
Step-:1
Create an Instant cloud flow, expand the Manual trigger action, and add a Text input to get the Folder name from users.
Step-:2
Select + New step and choose the Get Files (Properties only) action from the action trigger. Then Provide the details below:
- Site Address – Choose SharePoint site address
- Library Name – Choose the document library
- Filter Query – apply the below filter query code
ContentType eq 'Folder'
Step-3:
Add a new step, and select filter array action from action triggers. In the form, the action passes the dynamic content values. And check the condition Select the dynamic content Name Values is equal to the Folder Name.
Step-4:
Add a compose action and check the length of the filter array. Pass the below expression as an input value.
length(body('Filter_array'))
Step-5:
- Select + new step and Add a condition control to check if the output value is less than or equal to 0. If yes, then we will create a folder. else, we will not create a folder.
- If yes add and create new folder action. Then configure the SharePoint site address, SharePoint List name, and then pass the dynamic folder name.
- If no add a compose action and pass the input as FolderName Exist.
Step-6:
Save and Run the flow by selecting the Run flow option.
Case 1:
In the screenshot below, you can see the existing folders presented in the document library.
Here I will pass the Folder name as TestDocuments and select the run flow option.
You can see our flow ran successfully and doesn’t create any folders in the SharePoint library because the folder is existing in a document library.
Case:2
In the same way, I am going to pass the Folder name as HRDetailsDocuments and select the run flow option.
You can see our flow ran successfully, and we created a new folder in the SharePoint library because the folder does not exist in a document library.
In the below screenshot, you can see that the folder has been created in the document library.
This is how to create a SharePoint folder if not exist using the Filter array action inPower Automate.
In this Power Automate tutorial, we have learned how to create a folder in the SharePoint library using Power Automate. We have also discussed how to create a folder if not exist using Power Automate and the different ways we can achieve it.
You may also like:
- Convert HTML to PDF in Power Automate
- Convert base64 to an image file in Power Automate
- Send Teams Messages using Power Automate
- Convert XML to CSV using Power Automate
- Convert CSV to Excel using Power Automate
- Power Automate Filter Query If Blank
After working for more than 15 years in Microsoft technologies like SharePoint, Office 365, and Power Platform (Power Apps, Power Automate, and Power BI), I thought will share my SharePoint expertise knowledge with the world. Our audiences are from the United States, Canada, the United Kingdom, Australia, New Zealand, etc. For my expertise knowledge and SharePoint tutorials, Microsoft has been awarded a Microsoft SharePoint MVP (9 times). I have also worked in companies like HP, TCS, KPIT, etc.