cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
jrmaier
Regular Visitor

Delete local files in specific folder after "x" days

Hello,

 

I am a beginner at Power Automate. I created a scheduled export from Power BI to a CSV file that includes a date/time stamp in the name. I'd like to be able to delete files that are 7 days old so this folder doesn't grow out of control. Thank you for any help you can give!

 

Jim

1 ACCEPTED SOLUTION

Accepted Solutions
jrmaier
Regular Visitor

@ScottShearer Thank you so much. That worked! I greatly appreciate your help and taking the time to share your talents!

View solution in original post

7 REPLIES 7
ScottShearer
Super User
Super User

@jrmaier 

See my example below.  Not the filter query and the single quotes around the expression - they are required.  The expression that I used can be seen in the action note.

image.pngimage.pngimage.png

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

Scott
jrmaier
Regular Visitor

@ScottShearer I'm having trouble figuring out the filter query. Could you explain that a little more, please?

Is it possible to have this look for files in my OneDrive or Local folder instead?

@jrmaier 

See below for a Flow that will delete files more than 7 days old from OneDrive.  OneDrive does not provide the created date so I'm using last modified date.  If the files are static, the create and modified dates should be the same.

image.png

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

Scott
jrmaier
Regular Visitor

@ScottShearer 

I think I have everything correct but received this error. Unable to process template language expressions for action 'Condition' at line '0' and column '0': 'The template language function 'addDays' expects a timestamp as the first parameter, the number of days to add as the second parameter, and an optional format string as the third parameter. The function was invoked with '0' parameter(s). Please see https://aka.ms/logicexpressions#adddays for usage details.'.

 

Snag_10ea27a7.png

jrmaier
Regular Visitor

List of files in the folder I am targeting. 

Snag_10ec83a8.png

@jrmaier 

The error is telling you that it doesn't like the addDays() expression.

Take a look at the screen shot that I posted above.  In the condition, I placed the expression that you need to use in the notes area at the top of the condition for documentation purposes.  It needs to be entered in total in the expression window.

ALSO, CHANGE THE -1 IN THE EXPRESSION TO A -7.  OTHERWISE YOU WILL DELETE FILES OLDER THAN 1 DAY.

In addition, change the condition from "equal to" to less than or equal to

image.png

 

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

Scott
jrmaier
Regular Visitor

@ScottShearer Thank you so much. That worked! I greatly appreciate your help and taking the time to share your talents!

Helpful resources

Announcements
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Difinity Conference 2022

Difinity Conference 2022

Register today for two amazing days of learning, featuring intensive learning sessions across multiple tracks, led by engaging and dynamic experts.

European SharePoint Conference

European SharePoint Conference

The European SharePoint Conference returns live and in-person November 28-December 1 with 4 Microsoft Keynotes, 9 Tutorials, and 120 Sessions.

Users online (4,510)