How to Delete File From SharePoint Using Power Automate? [With Various Examples]

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:

delete file power automate

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).

power automate delete file from sharepoint

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.

delete file sharepoint power automate

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.

sharepoint delete file power automate

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 File From SharePoint using Power Automate

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:

Delete Files in SharePoint Folder using Power Automate

Now follow the below steps:

1. In the Power Automate, create an Instant Cloud flow. Choose the trigger flow to trigger a flow manually.

power automate delete sharepoint file

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.

Delete Files in SharePoint Folder in Power Automate

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.

How to Delete Files in SharePoint Folder using Power Automate

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.

How to Delete Files in SharePoint Folder in Power Automate

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

Power Automate Delete Files in SharePoint Folder

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.

power automate delete files in sharepoint folder

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.

power automate delete sharepoint file

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')}'
delete sharepoint file power automate

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.

power automate delete file in sharepoint folder

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

How to Delete Files Older Than Specific Date using Power Automate

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).

power automate delete sharepoint file

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.

Power Automate delete all files in onedrive folder

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.

Delete All Files in the OneDrive Folder using Power Automate

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

How to Delete All Files in the OneDrive Folder using Power Automate

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.

Delete Files in Local Desktop using Power Automate

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).

power automate delete sharepoint file

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.

How to Delete Files in Local Desktop using Power Automate

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.

How to Delete Files in Local Desktop in Power Automate

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

Power Automate Delete Files in Local Desktop

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:

Power Automate Delete Files From SharePoint Recycle Bin

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

Delete Files From SharePoint Recycle Bin using Power Automate

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.

power automate delete files from recycle bin

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 : *
How Power Automate Flow delete files from recycle bin

Now click on save and run the flow manually. You can see that all files have been deleted from that document library.

How to Delete Files From SharePoint Recycle Bin in Power Automate

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

Delete Files From SharePoint Recycle Bin in Power Automate

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.

Power Automate Delete a Specific File From 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).

Delete a Specific File From SharePoint Document Library using Power Automate

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.

Delete a Specific File From SharePoint Document Library in Power Automate

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.

Power Automate Delete Specific File From SharePoint Document Library

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).
How to Delete a Specific File From SharePoint Document Library using Power Automate

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 a Specific File From SharePoint Document Library Power Automate

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.

Delete PDF Files Using Power Automate

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).

Delete PDF Files in Power Automate

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.

Power Automate Delete PDF Files

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.
Power Automate Delete PDF Files in SharePoint document library

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.

Power Automate Delete PDF Files SharePoint document library

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.

How to Delete PDF Files Using Power Automate

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:

  • 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.

  • 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.

  • >

    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…