How to Delete SharePoint Folders Using Power Automate? [2 Various Ways]

While working on an Employee Leave Request App application, I had to delete the empty folders in the document library using Power Automate. Unfortunately, the Delete folder action is not present in Power Automate.

After some research, I found two ways to delete a folder in the SharePoint document library using Power Automate. Such as:

  • Delete SharePoint folders using Power Automate Send an HTTP request to SharePoint action
  • Delete SharePoint folders using Power Automate Delete Item action

In this tutorial, I will cover how to delete SharePoint folders using Power Automate. Also, I will explain, below mentioned topics:

  • Delete a SharePoint document library folder If it exists with a specific name
  • Delete multiple SharePoint library folders using Power Automate
  • Delete empty folders in the SharePoint library using Power Automate

Delete Specific SharePoint Document Library Folder using Power Automate

I have a SharePoint document library [Payroll Records], where different types of files and folders are present. Within the mentioned document library [Payroll Records], I wanted to delete a specific folder named ‘Marketing‘.

SharePoint Document Library:

Power Automate delete Folder exists

Note:

Unfortunately, Delete folder action is not present in Power Automate SharePoint connector. Instead, we can use the SharePoint Delete item action to remove folders from SharePoint document libarary.

Follow the instructions below to create a flow:

1. Browse https://make.powerautomate.com to open the Power Automate Home page -> Instant cloud flow -> Manually trigger a flow trigger, where we can run the flow with one button click.

2. Next, add Get folder metadata to get the folder ID of a specific folder. Configure the parameters:

  • Site Address: Select the SharePoint site from the drop-down where your SharePoint library folders are present.
  • File Identifier: Choose the folder you want to delete from the Open folder icon.
How to delete a SharePoint folder using Power Automate

3. After that, take the Delete item action to remove the SharePoint library folder. Set the properties as below:

  • Site Address: Choose the SharePoint site.
  • List Name: Select a custom value to enter the library name.
  • Id: Choose to add ItemId from the dynamic content of the Get folder metadata.

Important:

In Power Automate Delete item action, List Name parameter only displays all the lists that are present in the SharePoint site. We need give document library name as a custom value.

Deleting Specific Folders in a Specific Library by using Power Automate

Now, the flow is ready. Click on the Save button. Test the flow manually.

4. When the flow runs successfully, you can see that the folder [Marketing] I showed above has been deleted from the SharePoint document library.

Refer to the image:

Power Automate delete specific folder in document library

Delete Multiple Folders in SharePoint Document Library Using Power Automate

I will use the SharePoint document library [Payroll Records] with files and folders. I wanted to delete multiple folders in this document library.

Delete multiple folders in SharePoint with MS Flow

Follow the steps below:

1. Create Instant cloud flow on the Power Automate -> Manually trigger a flow.

2. add the Get files [properties only] action to fetch all the documents from the SharePoint document library.

Set the parameters like Site Address and Library Name.

Power Automate delete all SharePoint folders

3. Then, add a Condition control action to fetch only folders from the SharePoint document library.

Set the given values:

Choose ValueOperatorChoose Value
IsFolderis equal totrue
How to Delete multiple in SharePoint Online Using Power Automate

For each loop, the dynamic body/value of Get files (properties only) will be added.

4. Under the True branch, add the Delete item action. Set the required parameters:

  • Site Address: Choose the SharePoint site where the document library is present.
  • List Name: Enter the custom value [Provide library display name]
  • Id: Add ID from the dynamic content of Get files (properties only) outputs.
Power Automate delete all folders from SharePoint

Once the flow is ready, click on the Save button. Then, Test the flow.

5. You can see the flow will run successfully without generating any errors.

How to delete all SharePoint Folder in Library using Power Automate

Output:

Go back to the SharePoint library and refresh the page. The library folders have been deleted.

Deleting Multiple folders in SharePoint by Power Automate

This is how we can delete multiple folders in the SharePoint document library using Power Automate.

Delete Empty Folders in SharePoint Document Library Using Power Automate

For this example, I will take a SharePoint document library named [Budget Cost Files], which consists of files and folders. I wanted to eliminate all the empty folders in this SharePoint library.

See the SharePoint document library [Budget Cost Files]:

Power Automate delete empty folder in document library

Important:

In Power Automate SharePoint connector, Delete folder action is not present. Instead, we can use Power Automate Send an HTTP request to SharePoint action.

Check out the steps:

1. Add button flow in Power Automate, where a user can trigger a flow by one click.

2. Next, add a Send an HTTP request to SharePoint action to get the folders from the SharePoint document library.

Configure properties:

ParametersValues
Site AddressChoose site from drop-down
MethodGET
Uri_api/web/GetFolderByServerRelativeUrl(‘/sites/AllyFinancialBank/BudgetCostFiles’)/Folders
Headers{ “accept”: “application/json;odata=nometadata” }

I have renamed the action to Get Folders.

Uri: _api/web/GetFolderByServerRelativeUrl('/sites/AllyFinancialBank/BudgetCostFiles')/Folders
Replace SharePoint document library name
How to delete empty SharePoint folders using Power Automate

3. After that, take Filter array action to filter the output of the previous action. Ensure to set the parameters:

  • From: Add body(‘GetFolders’)?[‘value’] in the expression.
  • Filter Query: Paste the code given below.

Click on Edit in advanced mode to insert the code.

and(equals(item()?['ItemCount'], 0), not(equals(item()['Name'], 'Forms')))

Important:

In the above code, first part checks if the item count is equal to zero and second part check if folder name is not equal to Forms. Where, Forms is an internal folder in every document library that can not be deleted.

Delete empty folder SharePoint using Power Automate

4. Then, add Apply to each action to loop through each folder coming from the output of the filter array.

  • Select an output from previous steps: Select Body from dynamic content of Filter array.
Power Automate How to delete SharePoint empty Folder

5. Inside the loop, add one more Send an HTTP request to SharePoint action to delete the empty SharePoint document library folders.

Configure the required parameters:

  • Site Address: Choose the desired SharePoint site
  • Method: Select DELETE from the drop-down
  • Uri: Insert the code placed below
_api/web/GetFolderByServerRelativeUrl('/sites/AllyFinancialBank/BudgetCostFiles/@{items('Apply_to_each')['Name']}')
File Name can be entered from the Expression tab.
Replace Site name,Library name
Delete Sharepoint Library empty Folder using Power Automate

6. Now the flow created sucessfully. Click on Save. Then, click on Test. Run the flow manually.

7. Once the flow runs successfully, empty folders in the specific document library will be deleted.

After deleting empty folders [Budget Cost Files]:

Delete All empty folders in SharePoint using Power Automate

Conclusion

I have discussed the following topics such as:

  • Deleting a SharePoint-specific folder in Power Automate
  • Deleting multiple SharePoint document library folders by Power Automate
  • Delete all empty folders in SharePoint using Power Automate

You may also visit:

>

Build a High-Performance Project Management Site in SharePoint Online

User registration Power Apps canvas app

DOWNLOAD USER REGISTRATION POWER APPS CANVAS APP

Download a fully functional Power Apps Canvas App (with Power Automate): User Registration App

Power Platform Tutorial FREE PDF Download

FREE Power Platform Tutorial PDF

Download 135 Pages FREE PDF on Microsoft Power Platform Tutorial. Learn Now…