Power Automate delete all files in SharePoint folder

Do you want to delete all files from SharePoint and Onedrive folder? In this Power Automate tutorial, we will see how to delete all files in a SharePoint folder.

Also, we will cover how to delete files from the OneDrive folder using Power Automate. Finally, we will cover how to delete files older than 30 days from the SharePoint folder using Power Automate.

Sometimes, when you’re using a tool like SharePoint or OneDrive for a task, you might create a file for a specific purpose while the task is happening.

However, once the task is done, you don’t need that file anymore. It’s a good idea to remove or delete it so you don’t end up with unnecessary files taking up space in your storage.

To do this process automatically, we can use the Power Automate Delete file action available for SharePoint and OneDrive.

Power Automate delete all files in SharePoint folder

Here, we will see how to delete all files in the SharePoint folder in Power Automate.

For example, I have a SharePoint document library, and inside the library, I have a SharePoint folder called ‘Invoices[Not required]’, and we need to delete all files from this SharePoint folder. For this, follow the below steps.

 delete files in folder power automate

1. In Power Automate Cloud, create an Instant cloud flow that will trigger Manually.

power automate delete file

2. Next, we will get files from the folder; for this, click on the +New step -> select ‘Get files in Folder (Properties only)’action. Then provide the information below

  • Site address: Provide the SharePoint site address
  • Library name: Provide the Library name
  • Limited entries to folder: Select the folder path from dynamic content
  • Include Nested Items: Select Yes
power automate delete all files in sharepoint folder

3. Now, we will delete all files available in the folder; for this, click on the +new step -> select Delete file action. Then provide the below information:

  • Site address: Provide the SharePoint site address
  • File identifier: Select the Identifier from dynamic content. This will automatically add Apply to each action to the flow.
power automate delete files in folder

4. Now run the flow manually, and you can see all the files deleted from SharePoint folder in Power Automate.

power automate delete files in sharepoint folder

This is how to delete all files in the SharePoint folder using Power Automate.

See also  How to Create and Delete an Item from a SharePoint List using Power Automate Desktop?

Power Automate delete all files in OneDrive folder

Here, we will see how to delete all files in the Onefrive folder using Power Automate.

For example, I have a OneDrive folder, i.e., ‘Invoices[Not needed]’, and I need to delete all files available in a folder using Power Automate. For this, I have followed the below steps.

power automate delete all files in onedrive folder

1. In Power Automate Cloud, create an Instant cloud flow, which will trigger manually.

Power Automate delete files onedrive folder

2. Next, we will get all files from the Onedrive folder. For this, click on +New step -> select List files in folder action. Provide the below information:

  • Folder: Select the path of the folder.
delete files in oneDrive power automate

3. Now, we will delete the file from the Onedrive folder; for this, click on the +New step -> select Delete file action. Then provide the below information:

power automate delete all files in onedrive

4. Now save and run the flow manually, and you can see all files are deleted from the OneDrive folder.

power automate delete files in folder onedrive

This is how to delete all files from the OneDrive folder using Power Automate.

Power Automate delete files older than

Here, we will see how to delete files that are older than 30 days in Power Automate.

For example, I have a Sharepoint folder called ‘Excel Sheets’, i need to delete files that are older than 30 days using Power Automate; for this follow the below steps.

power automate delete files older than

1. In Power Automate Cloud, create an Instant cloud flow and that will trigger Manually.

power automate delete file

2. Next, we will get files from the folder that are older than 30 days; for this, click on the +New step -> select ”action. Then provide the information below

  • Site address: Provide the SharePoint site address
  • Library name: Provide the Library name
  • Limited entries to folder: Select the folder path from dynamic content
  • Include Nested Items: Select Yes
  • Filter query: Provide the below expression:
Created lt'@{addDays(utcnow(),-30,'yyyy-MM-dd')}
power automate delete files older than 30 days

3. Now, we will delete all files in the folder older than 30 days; for this, click on the +new step -> select Delete file action. Then provide the below information:

  • Site address: Provide the SharePoint site address.
  • File identifier: Select the Identifier from dynamic content. This will automatically add Apply to each action to the flow.
power automate delete files in folder

4. Now run the flow manually, and you can see all the files deleted from the SharePoint folder in Power Automate.

See also  How to Create and Delete an Item from a SharePoint List using Power Automate Desktop?
power automate delete files older than X days

This is how to delete all files in the SharePoint folder that are older than 30 days using Power Automate.

Conclusion

In this Power Automate tutorial, we saw how to delete all files in the SharePoint folder using Power Automate. Also, we cover the below topics

  • Power Automate delete all files in OneDrive folder
  • Power Automate delete files older than 30 days

You may also like:

  • This is wow! Exactly what I was looking for. I will the way you teach and guide. It’s vey helpful and intuitive. I will like to know if you have a dedicated online training that covers power automate and sharepoint.

  • Hi, this is a great post. Exactly what I am looking for.
    I needed to create a workflow to delete files in a SP library folder after x number of days. Unfortunately, my workflow is getting a cryptic error message with the Delete file action. “An action failed. No dependent actions succeeded.” I debugged the workflow using simple counters to ensure the condition set is correct. All working fine with just the counters… then I added the Delete action and the workflow failed with that error.
    I posted the question on MS forum (https://powerusers.microsoft.com/t5/Using-Flows/Automatically-delete-files-in-Document-Library-after-X-days/m-p/2140280#M38855) but unfortunately there’s no response yet.

    Do you know how to fix this? Greatly appreciate any assistance/suggestion.
    Thanks

  • >