web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Delete files from fold...
Power Automate
Answered

Delete files from folder after 180 days

(0) ShareShare
ReportReport
Posted on by 26

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

Categories:
I have the same question (0)
  • Verified answer
    ScottShearer Profile Picture
    25,290 Most Valuable Professional on at

    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.

  • Verified answer
    v-xida-msft Profile Picture
    Microsoft Employee on at

    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

     

  • Verified answer
    Weatherman Profile Picture
    26 on at

    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

     

  • Verified answer
    Weatherman Profile Picture
    26 on at
    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

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Automate

#1
David_MA Profile Picture

David_MA 251 Super User 2026 Season 1

#2
Haque Profile Picture

Haque 239

#3
Expiscornovus Profile Picture

Expiscornovus 220 Most Valuable Professional

Last 30 days Overall leaderboard