Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Automate - Using Flows
Answered

Automatically delete files in Document Library after X days

(0) ShareShare
ReportReport
Posted on by

Hi,

 

How can i create a flow so that everytime a file is created/added in a SharePoint Document Library, that the particular file than will be deleted in lets say in "7 days".

 

The point is that the no files older than 7 days will stay in the Document Library.

 

Thanks...

 

 

 

  • TC416 Profile Picture
    37 on at
    Re: Automatically delete files in Document Library after X days

    I initially set up a bunch of variables for URL and folder paths, and retention duration etc etc.  On saving the workflow, PA did not throw any error.  However when I tried running it, it triggered that error.  The error was subsequently traced to the use of some of the variables... in particular, the ones with URLs.   Once I have the URL statically coded in the flow instead of in variables, then everything works.

  • knowak Profile Picture
    7 on at
    Re: Automatically delete files in Document Library after X days

    How did you solve your case?

  • FabvE Profile Picture
    79 on at
    Re: Automatically delete files in Document Library after X days

    Hi,

    I stumbled upon this thread as I have the same problem. 🙂
    What happens if the result list of old files is larger than the magic 5000 threshold? Are only the first 5000 deleted?

    Best regards

  • henrybs Profile Picture
    3 on at
    Re: Automatically delete files in Document Library after X days

    Hi @JBlaiser, thank you for posting this update. I am using the flow and it is happily working. Can you advise how the flow can be adapted to also delete folders/subfolders that are also older than xx days? Thank you

  • TC416 Profile Picture
    37 on at
    Re: Automatically delete files in Document Library after X days

    Nevermind my previous post. The issue is resolved.

  • TC416 Profile Picture
    37 on at
    Re: Automatically delete files in Document Library after X days

    I have a similar workflow that delete files after xx number of days.  I tested the workflow by incrementing a counter when condition is matched.  Everything runs correctly.  But when I add the Delete action, then i get this error message "An action failed. No dependent actions succeeded.".  
    Anyone has any idea how to fix this?   Thanks.

    TC416_0-1683228947621.png

     

  • Community Power Platform Member Profile Picture
    on at
    Re: Automatically delete files in Document Library after X days

    @gamoraes And how would you change the flow if you want to delete file older than lets say 14 hours 

    I will appreciate if you can share a screenshot for that flow 

     

    thanks and regards

  • ScottTardif Profile Picture
    2 on at
    Re: Automatically delete files in Document Library after X days

    When using the flow that you stated, I am running into issue because there are subfolders that are causing the flow to fail.  Any idea how to circumvent the problem?

     

    Edit:

    I figured out that I could add to the conditional statement with an "And" the "IsFolder" "is equal to" "false".  So, as long as the item is not a folder the conditional statement would run.

  • lucktw Profile Picture
    3 on at
    Re: Automatically delete files in Document Library after X days

    Hello, Valentina!

     

    Did you find any solution to delete folders and sub-folders?

    I'm stuck on it 😅

  • valentinaG Profile Picture
    2 on at
    Re: Automatically delete files in Document Library after X days

    Hi 

    and if I wanted to delete folders and sub-folders as well as files?

    Thanks

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

Featured topics

Restore a deleted flow