cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
AdamInLondon
Helper II
Helper II

Automatically delete files in a document library more than four months old

Hi I have a simple request that I just cant figure out.

I have a document library called Parking Permits which is just a whole bunch of simple Word documents.

I want a scheduled Flow to run ever month to simply find any file more than 120 days old and delete it.

So far I have 

Recurrence

Get files (properties only) from the Document Library "Parking Permits"

Apply to each = Value

Then I cant work out the Condition step.

How do I get that to say 

Created date is more than 120 days in the past ?

I have found a couple of posts on this subject but their Condition step looks different to what I see ?

AdamInLondon_0-1626968578735.png

 

 

any help gratefully received as ever...

 

5 REPLIES 5
DamoBird365
Super User
Super User

Hi @AdamInLondon 

 

You could just apply a filter on the get files action.

 

Created lt 'adddays(formatDateTime(Utcnow(),'yyyy-MM-dd'),-120)'

 

DamoBird365_0-1626973087292.png

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Cheers,
Damien


P.S. take a look at my new blog here and like & subscribe to my YouTube Channel thanks 😉

AdamInLondon
Helper II
Helper II

Thank you! This looks promising.

So , I apply the filter in the Get files (properties only) step. How do I then tell the flow to delete those files ??

Add a delete file action and insert the id from get files. The flow will create a loop automatically. You might want to turn on concurrency for the apply to each.

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Cheers,
Damien


P.S. take a look at my new blog here and like & subscribe to my YouTube Channel thanks 😉

AdamInLondon
Helper II
Helper II

Hi that makes sense but I get this error:

 

The expression "Created lt 'adddays(formatDateTime(Utcnow(),'yyyy-MM-dd'),-120)'" is not valid. Creating query failed.
clientRequestId: 8c89e23c-8982-4b99-abfe-49fd848ce7fe
serviceRequestId: 8c89e23c-8982-4b99-abfe-49fd848ce7fe

 

Here is what I have:

Screenshot 2021-08-10 at 14.19.19.pngScreenshot 2021-08-10 at 14.19.43.png

Hi @AdamInLondon 

 

your expression has been added as a string, make sure you add the expression via the expression tab and update. It should appear as a block. Check out my first screenshot.

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Cheers,
Damien


P.S. take a look at my new blog here and like & subscribe to my YouTube Channel thanks 😉

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Users online (2,136)