Forum Discussion
Deleting Files Automatically after 3 Months
- Aug 25, 2021
Filmanac yes this can be done with a simple flow in Power Automate as shown below.
1. Your trigger needs to be a recurrence schedule which you set to 1 day (and the timezone and time you want it to run) so that it checks the library every day:
For the first action select the SharePoint get files (properties only), select your site and the Document library. But you only want to bring back those items that were created over 3 months ago, the rest you can ignore. So in the Filter Query field add the following:
Created lt '{expression}addDays(utcNow(), -90){/expression}'(Created is the column that is being checked, lt = less than, utcNow() = today, -90 is 90 days ago).
Don't forget to put the expression inside single quotes!
It will default to bringing back items from the entire document library but you can limit it to a specific folders by clicking the folder icon on the right and selecting the folder:
Finally, add a SharePoint delete file action. It will automatically wrap itself in an apply to each (as the previous action was get items). Select Identifier from the dynamic content box. The items that were brought back by the get items will then be deleted.
Rob
Los Gallardos
Microsoft Power Automate Community Super User
Filmanac yes this can be done with a simple flow in Power Automate as shown below.
1. Your trigger needs to be a recurrence schedule which you set to 1 day (and the timezone and time you want it to run) so that it checks the library every day:
For the first action select the SharePoint get files (properties only), select your site and the Document library. But you only want to bring back those items that were created over 3 months ago, the rest you can ignore. So in the Filter Query field add the following:
(Created is the column that is being checked, lt = less than, utcNow() = today, -90 is 90 days ago).
Don't forget to put the expression inside single quotes!
It will default to bringing back items from the entire document library but you can limit it to a specific folders by clicking the folder icon on the right and selecting the folder:
Finally, add a SharePoint delete file action. It will automatically wrap itself in an apply to each (as the previous action was get items). Select Identifier from the dynamic content box. The items that were brought back by the get items will then be deleted.
Rob
Los Gallardos
Microsoft Power Automate Community Super User
Thank you for the instructions on this. It made everything much clearer. The flow runs successfully in both test and when left to itself based on the time margin, however, files older than 3 months/90 days are not being deleted.
I have made sure to include nested items, so not sure what is stopping things now. I will need to dig a bit deeper.
Thank you for your help so far though.
- RobElliottAug 26, 2021Silver ContributorIf you post a screenshot of your flow then we can see where you've gone wrong.
- FilmanacAug 26, 2021Copper Contributor
RobElliott I have attached two screenshots of the flow. I haven't included it in the screenshot, but the code I'm using for the filter query is 'addDays(utcNow(),-90).
I have removed the actual SharePoint site address and the specific folder I'm using.