Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Automate - Building Flows
Answered

Delete files after 3 days - flow works except gives an error.

(0) ShareShare
ReportReport
Posted on by 10

I wrote a script in Power Automate to automatically delete files after X amount of days that the file was created.  It deletes the files, but gives an error:

tobrien1_0-1645472232306.png

 

This is what my flow looks like:

 

tobrien1_2-1645472382444.png

 

tobrien1_3-1645472453508.png

the Expression i'm using is adddays(utcnow(),-3,'yyyy-MM-dd') 

  • tobrien1 Profile Picture
    10 on at
    Re: Delete files after 3 days - flow works except gives an error.

    All of the files that should be deleted are gone, so the flow works it's just the error that is bugging me.

  • ScottShearer Profile Picture
    25,228 Most Valuable Professional on at
    Re: Delete files after 3 days - flow works except gives an error.

    @tobrien1 

    Are all the files deleted that match your criteria even though you get the error or is it failing on a single file all the time?

     

  • tobrien1 Profile Picture
    10 on at
    Re: Delete files after 3 days - flow works except gives an error.

    I've tried it that way and again the files delete, but the same error message and failure point:

     

    tobrien1_0-1645475216768.png

     

    I did take your advice and turned on Library and Folder based features and set the retention, but i'd still like to know why my flow fails.  Thanks for your help.

  • Verified answer
    ScottShearer Profile Picture
    25,228 Most Valuable Professional on at
    Re: Delete files after 3 days - flow works except gives an error.

    Can you post a screen shot of a run with the error that shows where the error happened.

    Also, you would be better of using a filter query rather than a condition - then just loop through and delete everything returned.  

    Filter query would look like this:

    Created lt 'addDays(utcNow(), -3,'yyyy-MM-dd')

     

    Finally, you don't need a Flow at all for this - SharePoint will do it for you automatically.  First, go to Site collection features and activate Library and Folder Based Retention Feature.  Then go to the library settings and click on Information management policy settings.  Click on Document and add a retention stage that deletes documents after a specified period of time.

     

     

     

     

  • tobrien1 Profile Picture
    10 on at
    Re: Delete files after 3 days - flow works except gives an error.

    This is in the gov't cloud if that makes any difference

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

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 497 Super User 2025 Season 1

#2
David_MA Profile Picture

David_MA 436 Super User 2025 Season 1

#3
Riyaz_riz11 Profile Picture

Riyaz_riz11 244 Super User 2025 Season 1