How to Create a Folder in SharePoint using Power Automate?

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.

create a Folder in SharePoint using Power Automate

Expand the Manual trigger action and add a Text input to get the Folder name from users.

create a Folder in SharePoint using Power Automate flow

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.
How to create a Folder in SharePoint using Power Automate

Save and Run the flow, Enter the Folder Name, and select the run flow option.

Example to create a Folder in SharePoint using Power Automate flow

Once the flow ran successfully like below:

How to create a Folder in SharePoint using Power Automate flow

The New folder has been created in the SharePoint document library using Power Automate flow.

Example to create a Folder in SharePoint using Power Automate

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.

How to create a SharePoint folder if not exists

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'
How to create a SharePoint folder if not exists example

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.

create a SharePoint folder if not exists

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.

Example to create a SharePoint folder if not exists
  • 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.
Example to create a SharePoint folder if not exists using flow

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.
create a SharePoint folder if not exists using flow

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.

How to create a SharePoint folder if not exists using flow

Here I will pass the Folder name as HRDetails and select the run flow option.

create a SharePoint folder if not exists using Power Automate flow

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.

create a SharePoint folder if not exists using the flow

Case:2

In the same way, I am going to pass the Folder name as EmployeeUserManuals and select the run flow option.

create SharePoint folder if not exists using Power Automate flow

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.

create a SharePoint folder if not exists using the Power Automate flow

In the below screenshot, you can see that the folder has been created in the document library.

Example to create a SharePoint folder if not exists using the Power Automate flow

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.

create a SharePoint folder if not exist using Power Automate REST API

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'
How to create a SharePoint folder if not exist using Power Automate REST API

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.

How to create SharePoint folder if not exist using Power Automate REST API

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]
create a SharePoint folder if not exist using REST API in Power Automate flow

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']}'
}
create a SharePoint folder if not exist using REST API in Power Automate

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.

Example to create a SharePoint folder if not exist using REST API in Power Automate flow

Here I am going to pass the Folder name as ConfidentialDocumentsand select the run flow option.

Example to create a SharePoint folder if not exist using REST API in Microsoft flow

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.

Example to create SharePoint folder if not exist using REST API in Microsoft flow

In the below screenshot, you can see that the folder has been created in the document library.

create a SharePoint folder if not exist using the Power Automate REST API

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'
create a SharePoint folder if not exist using Filter array action

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.

create a SharePoint folder if not exist using the Filter array

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'))
create a SharePoint folder if not exist using the Filter array action in power automate

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.
Example to create a SharePoint folder if not exist using the Filter array

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.

Example to create a SharePoint folder if not exist using Filter array action

Here I will pass the Folder name as TestDocuments and select the run flow option.

create a SharePoint folder if not exist using the Filter array in Power Automate

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.

create a SharePoint folder if not exist using Filter array in Power Automate

Case:2

In the same way, I am going to pass the Folder name as HRDetailsDocuments and select the run flow option.

create a SharePoint folder if not exist using Filter array action in Power Automate

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.

create a SharePoint folder if not exist using Filter array action in Power Automate flow

In the below screenshot, you can see that the folder has been created in the document library.

Example to create a SharePoint folder if not exist using Filter array action in Power Automate flow

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:

>