Forum Discussion
Filmanac
Aug 25, 2021Copper Contributor
Deleting Files Automatically after 3 Months
Hello, Is it possible to create a flow that will automatically delete files in specific SPO folders after 3 months? I have tried using a flow, but I am not experienced with them and am having tr...
- 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
LCSilliman
Dec 07, 2021Copper Contributor
RobElliott Thanks for this This flow doesn't seem to work for me, and I'm not entirely sure why, but it seems like it is looking for anything created exactly 3 days ago (I need things deleted more than 3 days old). So I've used Created It 'addDays(utcNow(), -3)', but I keep getting this error.
Am I missing something obvious?
Dan0365
May 11, 2022Copper Contributor
LCSilliman did you manage to solve your issue with the query failed ?
Am running in to the same problem!
Am running in to the same problem!
- anniewendelJun 23, 2023Copper Contributor
Dan0365 LCSilliman I'm also running into this error. Any advice? Were you able to get it resolved? Thank you!
- Dan0365Jun 26, 2023Copper Contributoranniewendel am afraid not and have ended up changing how users use the folder.
- LCSillimanJun 26, 2023Copper Contributor
anniewendel I've had no resolution to this issue, but it was because I don't have the appropriate rights in the enterprise version my workplace is using.