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

Flow - OneDrive - Delete files older than 30Days in Folder

Hi,

 

I cannot see this as an option in templates but can somebody help me design a flow that achives the following?

 

To automatically delete files in a Onedrive folder that are over 30days old?

 

Many thanks for the help

2 ACCEPTED SOLUTIONS

Accepted Solutions
lewisdhbrooks
Level: Powered On

Re: Flow - OneDrive - Delete files older than 30Days in Folder

Hi,

 

flow3.png
Still nothing, it's pulled in the LastModified date/time but the conditions are still false so no deleted files

Community Support Team
Community Support Team

Re: Flow - OneDrive - Delete files older than 30Days in Folder

Hi @lewisdhbrooks,

 

It seems that the Compose doesn't return repect value. Please enter the function under the Expression tab then check the return value. It should return a date time value but not the function itself.

 

Best regards,

Mabel Mao

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

Re: Flow - OneDrive - Delete files older than 30Days in Folder

Hi @lewisdhbrooks,

 

According to your description, I created a flow likes below.

 

The flow is triggered by a Button, followed by the OneDrive for Business action List files in folder, then add a Condition to check if the last modified time of the file is 30 days ago (as there is no dynamic content for Created date time, so I use last modified time instead). If yes, delete the file.

 

The code is:

@equals(formatDateTime(items('Apply_to_each')?['LastModified'], 'yyyy-MM-dd'),adddays(utcnow('yyyy-MM-dd'),-30))

 

Please check the following screenshot for a reference.

 1.PNG

 

 

Best regards,

Mabel Mao

Community Support Team _ Mabel Mao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
lewisdhbrooks
Level: Powered On

Re: Flow - OneDrive - Delete files older than 30Days in Folder

Awesome, thanks for this.  I've set it up and will test when the test files I've placed in Onedrive are a few days old.  I'll change the older than threshold for testing only and let you know

lewisdhbrooks
Level: Powered On

Re: Flow - OneDrive - Delete files older than 30Days in Folder

Hi,

 

So I've uploaded some files which are a day old and modified the time to this code but the flow has not deleted any of the files and the condition comes back as false for each file.

 

@equals(formatDateTime(items('Apply_to_each')?['LastModified'], 'yyyy-MM-dd'), adddays(utcnow('yyyy-MM-dd'), -1))

flow.png

 

 

Super User
Super User

Re: Flow - OneDrive - Delete files older than 30Days in Folder

Just so I am clear, did you upload the documents yesterday?

 

Can you post a screen shot of the files in the library showing the last modified date?

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

Scott
lewisdhbrooks
Level: Powered On

Re: Flow - OneDrive - Delete files older than 30Days in Folder

flow2.png

 

 

Community Support Team
Community Support Team

Re: Flow - OneDrive - Delete files older than 30Days in Folder

Hi @lewisdhbrooks,

 

I modified the flow configuration, please check the following flow configuration.

 

First, use the action initialize variable, set Name as LastModified, Type as String.

 

Then the action List files in folder. Specify the folder from which you want to get files.

 

Then under Apply to each, add the action Set variable, select dynamic content Last Modified Time for the Value field.

 

Then use a Compose action to format the LastModified time. The code is:

formatDateTime(variables('LastModified'),'yyyy-MM-dd')

 

Then configure the Condition using code likes below:

@equals(outputs('Compose_2'),formatDateTime(adddays(utcnow(),-3),'yyyy-MM-dd'))

 

Under the If Yes branch, add the Delete file action, select dynamic content Id from the trigger.

1.PNG

 

 

Please try again with it on your side.

 

Best regards,

Mabel Mao

Community Support Team _ Mabel Mao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
lewisdhbrooks
Level: Powered On

Re: Flow - OneDrive - Delete files older than 30Days in Folder

Hi,

 

flow3.png
Still nothing, it's pulled in the LastModified date/time but the conditions are still false so no deleted files

Community Support Team
Community Support Team

Re: Flow - OneDrive - Delete files older than 30Days in Folder

Hi @lewisdhbrooks,

 

It seems that the Compose doesn't return repect value. Please enter the function under the Expression tab then check the return value. It should return a date time value but not the function itself.

 

Best regards,

Mabel Mao

Community Support Team _ Mabel Mao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
lewisdhbrooks
Level: Powered On

Re: Flow - OneDrive - Delete files older than 30Days in Folder

Yep that worked but the flow failed as it tried to delete subfolders on top of the files in that subfolder

 

{
  "status"400,
  "message""Resource : '481915922BF7857F!71255' is a directory. This API works only on files",
  "source""api.connectorp.svc.ms"
}

Gecko
Level: Powered On

Re: Flow - OneDrive - Delete files older than 30Days in Folder

Anyone found a solution for this - seems struggling to get it working as I don't understand the condition statement.

Helpful resources

Announcements
firstImage

Microsoft Business Applications Virtual Launch Event

Watch the event on demand for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 Release Wave 2 Plan

Power Platform 2019 Release Wave 2 Plan

Features releasing from October 2019 through March 2020.

thirdimage

Flow Community User Group Member Badge

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

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 Flow Community Video Gallery!

Top Kudoed Authors
Users Online
Currently online: 214 members 4,312 guests
Please welcome our newest community members: