Last week, I was working on a Power Automate flow where I needed to delete a file from a SharePoint document library. The requirement was to automate removing outdated files based on specific criteria, ensuring that our document management process remains efficient and up to date.
In this tutorial, I will cover various methods to delete files using Power Automate, focusing on SharePoint and OneDrive. I will show you how to delete all files from a document library, remove outdated files based on specific criteria, and permanently delete files without sending them to the Recycle Bin.
Additionally, I will show you how to delete files from a local desktop folder using simple scenarios.
Delete File From SharePoint Using Power Automate
Now, I will tell you how to delete the SharePoint file using Power Automate.
For this example, I already created a SharePoint document library named PDFDocument:

Here, I want to delete all the files, so to do this, follow the below steps:
1. Go to Power Automate, click the Instant Cloud flow, enter the Flow name, and choose the trigger flow (i.e., manually trigger a flow).

2. Add the Get files (properties only) action from the SharePoint connector, which retrieves all the files in the document library. Then, select the Site Address and Library Name from the drop-down menu.

3. Add the ‘Delete file’ action and select the Site Address from the drop-down. For the File Identifier, choose ‘Identifier’ from the dynamic content of the ‘Get files’ action. After that, a ‘For Each’ loop will be automatically added.

Now, click Save and run the flow manually. Once it runs successfully, go to the SharePoint document library to see the files deleted successfully.

Delete Files in SharePoint Folder Using Power Automate
Imagine you’re managing a SharePoint folder named ‘Employee Reviews’ within a document library called ‘Certification Documents,’ and you want to delete all files.
For this example, I created a SharePoint document library named Certification Documents, and inside the document, I have a Folder named Employee Reviews:

Now follow the below steps:
1. In the Power Automate, create an Instant Cloud flow. Choose the trigger flow to trigger a flow manually.

2. Add the Get files (properties only) action from the SharePoint connector, which retrieves all the files and folders in the document library, then select the Site Address and Library Name from the drop-down.

3. Now, select ‘Get files (properties only)’ and expand the advanced parameters. Select ‘Limit Entries to Folder’ and choose your folder; in my case, it is /CertificationDocuments/Employee Reviews.

4. Add the ‘Delete file‘ action and select the Site Address from the drop-down. For the File Identifier, choose ‘Identifier’ from the dynamic content of the ‘Get files’ action. After that, a ‘For Each’ loop will be automatically added.

Now, click Save and run the flow manually. Once it runs successfully, go to the SharePoint document library to see all files deleted successfully.

Delete Files Older Than Specific Date Using Power Automate
Imagine your team has a SharePoint document library called “HR Documents,” where temporary files are uploaded daily for quick reference and sharing.

These reports are only relevant for the current and previous days; anything older is no longer needed. To keep the library organized and outdated files, we want an automated solution that will delete files older than 2 days.
To do this, follow the below steps:
1. I am creating an Instant Cloud flow using the ‘Manually trigger a flow’ trigger for this example. Alternatively, you can use a Scheduled Cloud flow, which runs daily.

2. Add the Get files (properties only) action from the SharePoint connector, which retrieves all the files and folders in the document library, then select the Site Address and Library Name from the drop-down and in the filter query, add the below expression:
Modified lt '@{addDays(utcNow(), -2, 'yyyy-MM-dd')}'
3. Add the ‘Delete file’ action and select the Site Address from the drop-down menu. For the File Identifier, choose ‘Identifier’ from the dynamic content of the ‘Get files’ action. This will automatically add a ‘For Each’ loop.

Now, click Save and run the flow manually. Once it runs successfully, go to the SharePoint document library to see files deleted successfully.

Similarly, to delete older files, you can increase the number in the addDays function to adjust how many days back the filter should apply.
Delete All Files in the OneDrive Folder Using Power Automate
I have a folder called ‘PDF Folder’ in OneDrive. We will create a flow to delete all files in this folder.
Now follow the below steps:
1. In the Power Automate, click the Instant Cloud flow, enter the Flow name, and choose the trigger flow (i.e., manually trigger a flow).

2. To retrieve all files from that folder in OneDrive, I add the List Files in Folder action from the OneDrive connector, then provide the Folder path.

3. Next, to delete files in the OneDrive folder, add the ‘Delete file’ action from the OneDrive connector. Provide the File field with the ‘Id’ from the dynamic content, which will automatically add an ‘Apply to each’ action.

Now click on Save and run the Flow manually. You can see that all files have been deleted from that OneDrive Folder.

Now you see all the files deleted in the OneDrive folder.
Delete Files in Local Desktop Using Power Automate
In this example, I will show you how to delete all files in a folder located on the local desktop.

Now follow the below steps:
1. In the Power Automate, click the Instant Cloud flow, enter the Flow name, and choose the trigger flow (i.e., manually trigger a flow).

2. To retrieve all files from that folder on the Local desktop, I add the List Files in Folder action from the File System connector, then provide the Folder path.

3. Next, to delete files in the local desktop folder, add the ‘Delete file’ action from the File System connector. Provide the File field with the ‘Id’ from the dynamic content, which will automatically add an ‘Apply to each’ action.

Now click on Save and run the flow manually. You can see that all files have been deleted from that local desktop folder.

Delete Files From SharePoint Recycle Bin Using Power Automate
To delete files permanently in SharePoint using Power Automate, we can create a flow that not only deletes the file but also bypasses the Recycle Bin. This means the file will be permanently removed and cannot be restored.
For this example, I created a SharePoint document library named HR Documents:

1. Go to Power Automate and create an Instant Cloud flow. Choose the trigger flow (i.e., manually trigger a flow).

2. Add the Get files (properties only) action from the SharePoint connector, which retrieves all the files and folders in the document library. Then, select the Site Address and Library Name from the drop-down menu.

3. Then add a Send an HTTP request to SharePoint action from sharePoint Connector with the below parameter:
- Site Address: Select the SharePoint site where you want the list to be created
- Method: Select “DELETE” as the method
- URI: Provide the below URI:
_api/web/getbytitle(‘Library Display Name')/items(Your item id here)- Headers: Add a key-value pair:
IF-MATCH : *
Now click on save and run the flow manually. You can see that all files have been deleted from that document library.

Then go to the SharePoint Recycle Bin, and you will see the files deleted.

How to Delete a Specific File From the SharePoint Document Library using Power Automate?
Suppose you have a document library named “Corporate Projects,” and you want to delete a specific file called “Currency Rates.csv” whenever it’s no longer needed. Instead of manually deleting it, you want Power Automate to remove it automatically based on a certain trigger.

Now follow the below steps:
1. Go to Power Automate, click the Instant Cloud flow, enter the Flow name, and choose the trigger flow (i.e., manually trigger a flow).

2. Add the Get files (properties only) action from the SharePoint connector, which retrieves the files in the document library. Then, select the Site Address and Library Name from the drop-down menu.

3. Now, we will add the Condition action to check whether that file exists.
In this Condition action, select the Name (from Get files(properties only) action) value equal to Currency Rates. It will automatically add for each loop.

4. Then, Add the Delete file action inside the true section and provide the below parameters:
- Site Address: The SharePoint site address from the drop-down menu.
- File Identifier: Provide an Identifier from the dynamic content of the Get files(properties only).

Now, click Save and run the flow manually. Once it runs successfully, go to the SharePoint document library to see the files deleted successfully.

How to Delete PDF Files Using Power Automate?
In this example, we see how to use Power Automate to delete only PDF files in the SharePoint document library.

Now follow the below steps:
1. Go to Power Automate, click the Instant Cloud flow, enter the Flow name, and choose the trigger flow (i.e., manually trigger a flow).

2. Add the Get files (properties only) action from the SharePoint connector, which retrieves all files in the document library. Then, select the Site Address and Library Name from the drop-down menu.

3. Use a “Filter array” action to filter the files for those with names that start with a specific prefix. In the “From” field, select the array of files returned by the “Get files” action, and set the condition to:
- From: Select body/value from dynamic content get files(properties only) action
- Filter Query: Select the File name with extension (from Get files(properties only) action) value that contains .pdf. It will automatically add for each loop.

4. Add a “Delete file” action within an “Apply to each” loop to delete each file that matches. In the File Identifier field, select the Identifier from the filtered array.

Now, click Save and run the flow manually. Once it runs successfully, go to the SharePoint document library to see all the PDF files deleted successfully.

In this tutorial, I covered how to delete files from SharePoint and OneDrive using Power Automate. I explained methods to remove all files from a document library, delete outdated files based on specific criteria, and permanently delete files without sending them to the Recycle Bin. Additionally, I Covered how to delete files from a local desktop folder.
Related Power Automate articles:
- Delete All Items in the SharePoint List Using Power Automate
- Restore Deleted Flow in Power Automate
- Delete all rows in Excel using Power Automate
- Delete all rows from a SharePoint Online list using Power Automate
- Get Days of Month in Power Automate
- Add Row to Excel Table Using Power Automate

After working for more than 18 years in Microsoft technologies like SharePoint, Microsoft 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 (12 times). I have also worked in companies like HP, TCS, KPIT, etc.
Hello!
Your guides are really well written and easy to follow – but I am looking for something that seems to be a step further:
I am trying to build a PowerAutomate workflow that will delete all files, folders and subfolders in a Document Library used for temporary staging.
Because the folders (and subfolders) can vary depending on the items being staged – I haven’t been able to find a solution that will recursively go through each level to clear things out.
We are a government office, so I’m not able to change the Retention policy settings and PowerShell is not really an option either.
Any help is appreciated!
Thank you.
Great article however I don’t want to delete the folders just files in the folders. How can I only delete the files and not the folders? Thanks
Hi Bro
for the Power Automate delete files older than 30 days
when I input “formatDateTime(item()[‘Created’],’yyyy-MM-dd’)” , it shown The expression is invalid. any Idea for this?
Hello, great post!! But, I get an error while trying to delete de file inside the folder:
Action ‘Delete_file’ failed7
El archivo /sites/CRM_Test/opportunity/Mesa Servicios TI 51891 – –54388– – problema al cargar datos_255C20D3B430EB11A813000D3A88A5FB no existe.
clientRequestId: 4bfa1db7-ed16-474a-9717-83665748f8a6
serviceRequestId: af0999a0-2068-3000-333e-5607f0f24e1b
It says that doesn’t exists.
Thanks a lot!
The “older than” simply doesn’t work. Files aren’t deleted. Flow Runs page says it was successful. But I don’t see that it got any files and the files are still in the folder.
Just tried your solution for “Power Automate delete files older than 30 days”. It seems to just delete one file at each run rather than all files that match the condition.