cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Weatherman
Level: Powered On

Delete files from folder after 180 days

Hello - can anyone tell me how to make a flow that will delete a file from Onedrive when it is 365 days old?

 

Thanks Dave

4 ACCEPTED SOLUTIONS

Accepted Solutions
Super User
Super User

Re: Delete files from folder after 180 days

Here is a link to a post that show how to do something very similar

 

You should be able to use this as your guide.

If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Scott

View solution in original post

Community Support Team
Community Support Team

Re: Delete files from folder after 180 days

Hi @Weatherman,

 

I agree with @ScottShearer's thought almost, but there is no way to get the created time of the files in your OneDrive folder within Microsoft Flow currently. We could only get the last modified time of the files in your OneDriver folder within Microsoft Flow currently.

 

I assume that the files in your OneDrive folder have not been modified after you created them within your OneDrive folder. I have made a test on my side and please take a try with the following workaround:

  • Add a Recurrence trigger, Interval set to 1 and Frequency set to Day.
  • Add a "List files in folder" action, specify Folder, Include headers field set to Yes.
  • Add a "Apply to each" action, input parameter set to output of "List files in folder" action.
  • Within "Apply to each" action, add a Condition, click "Edit in advanced mode", type the following formula:
@equals(formatDateTime(addDays(items('Apply_to_each')?['LastModified'], 46), 'MM/dd/yyyy'), utcNow('MM/dd/yyyy'))

Note: For testing, I delete a file from my OneDrive folder when it is 46 days old on my side. On your side, you should type the following formula within your Condition box:

@equals(formatDateTime(addDays(items('Apply_to_each')?['LastModified'], 365), 'MM/dd/yyyy'), utcNow('MM/dd/yyyy'))

Within "If/yes" branch of Condition, add a "Delete file" action, File field set to Id dynamic content of the "List files in folder" action.

 

Image reference:6.JPG

The flow works successfully as below:7.JPG

 

If you modified the files after you created them within your OneDrive folder, I afraid that there is no way to achieve your needs in Microsoft Flow currently.

 

 

Best regards,

Kris

 

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Weatherman
Level: Powered On

Re: Delete files from folder after 180 days

Hi Everyone

 

Thank you all so much for your replys, and so quickly as well.

I will take a look at the solutions and let you know how it goes.

As you said, once the file is uploaded into OneDrive it is never altered, so that is not an issue.

 

All the best Dave

 

View solution in original post

Weatherman
Level: Powered On

Re: Delete files from folder after 180 days

Hello and thank you so much for your suggestion. Based on what you sent me I did it a slightly different way. In the conditions box I put @lessOrEquals(items('Apply_to_each')['LastModified'], addDays(utcNow(), -30)) I choose 30 days this number can be altered to suit. This tests all the files in the chosen folder and deletes the ones 30 days or more old. I would paste the flow diagram but it will not allow me to insert an image here. All the best Dave

View solution in original post

4 REPLIES 4
Super User
Super User

Re: Delete files from folder after 180 days

Here is a link to a post that show how to do something very similar

 

You should be able to use this as your guide.

If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Scott

View solution in original post

Community Support Team
Community Support Team

Re: Delete files from folder after 180 days

Hi @Weatherman,

 

I agree with @ScottShearer's thought almost, but there is no way to get the created time of the files in your OneDrive folder within Microsoft Flow currently. We could only get the last modified time of the files in your OneDriver folder within Microsoft Flow currently.

 

I assume that the files in your OneDrive folder have not been modified after you created them within your OneDrive folder. I have made a test on my side and please take a try with the following workaround:

  • Add a Recurrence trigger, Interval set to 1 and Frequency set to Day.
  • Add a "List files in folder" action, specify Folder, Include headers field set to Yes.
  • Add a "Apply to each" action, input parameter set to output of "List files in folder" action.
  • Within "Apply to each" action, add a Condition, click "Edit in advanced mode", type the following formula:
@equals(formatDateTime(addDays(items('Apply_to_each')?['LastModified'], 46), 'MM/dd/yyyy'), utcNow('MM/dd/yyyy'))

Note: For testing, I delete a file from my OneDrive folder when it is 46 days old on my side. On your side, you should type the following formula within your Condition box:

@equals(formatDateTime(addDays(items('Apply_to_each')?['LastModified'], 365), 'MM/dd/yyyy'), utcNow('MM/dd/yyyy'))

Within "If/yes" branch of Condition, add a "Delete file" action, File field set to Id dynamic content of the "List files in folder" action.

 

Image reference:6.JPG

The flow works successfully as below:7.JPG

 

If you modified the files after you created them within your OneDrive folder, I afraid that there is no way to achieve your needs in Microsoft Flow currently.

 

 

Best regards,

Kris

 

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Weatherman
Level: Powered On

Re: Delete files from folder after 180 days

Hi Everyone

 

Thank you all so much for your replys, and so quickly as well.

I will take a look at the solutions and let you know how it goes.

As you said, once the file is uploaded into OneDrive it is never altered, so that is not an issue.

 

All the best Dave

 

View solution in original post

Weatherman
Level: Powered On

Re: Delete files from folder after 180 days

Hello and thank you so much for your suggestion. Based on what you sent me I did it a slightly different way. In the conditions box I put @lessOrEquals(items('Apply_to_each')['LastModified'], addDays(utcNow(), -30)) I choose 30 days this number can be altered to suit. This tests all the files in the chosen folder and deletes the ones 30 days or more old. I would paste the flow diagram but it will not allow me to insert an image here. All the best Dave

View solution in original post

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

firstImage

Incoming: New and improved badges!

We've given our badges an overhaul and also added some brand new ones!

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

sixthImage

Power Platform World Tour

Find out where you can attend!

seventhimage

Webinars & Video Gallery

Watch & learn from the Power Automate Community Video Gallery!

Top Kudoed Authors (Last 30 Days)
Users online (4,727)