Do you want to delete all files from a SharePoint or OneDrive folder? In this Power Automate tutorial, we will see how to delete all the files from a SharePoint folder using Power Automate.
We will also cover how to delete files from the OneDrive folder using Power Automate and 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 automate this process, we can use the Power Automate Delete file action available for SharePoint and OneDrive.
Power Automate delete all files in the 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.
1. In Power Automate Cloud, create an Instant cloud flow that will trigger Manually.
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
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.
4. Now run the flow manually, and you can see all the files deleted from the SharePoint folder in Power Automate.
This is how to delete all files in the SharePoint folder using Power Automate.
Delete all files from OneDrive folder using Power Automate
Here, we will see how to delete all files in the Onefrive folder using Power Automate.
For example, I have a OneDrive folder, ‘Invoices [Not needed]’, and I need to delete all files available in that folder using Power Automate. I have followed the below steps.
1. In Power Automate Cloud, create an Instant cloud flow, which will trigger manually.
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.
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:
- File: Select the ID from dynamic content. This will add Apply to each action in Power Automate.
4. Now save and run the flow manually, and you can see all files are deleted from the OneDrive folder.
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 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.
1. In Power Automate Cloud, create an Instant cloud flow and that will trigger Manually.
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')}
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.
4. Now run the flow manually, and you can see all the files deleted from the SharePoint folder in Power Automate.
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:
- Power Automate Get items
- Convert Time Zone in Power Automate
- Power Automate Leave Request Approval Example
- Auto Populate SharePoint List Columns Based on Value in One Column using Power Automate
- How to Create a File in Power Automate?
I am Bijay a Microsoft MVP (10 times – My MVP Profile) in SharePoint and have more than 17 years of expertise in SharePoint Online Office 365, SharePoint subscription edition, and SharePoint 2019/2016/2013. Currently working in my own venture TSInfo Technologies a SharePoint development, consulting, and training company. I also run the popular SharePoint website EnjoySharePoint.com
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.
i want these all with my one drive folders
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