Skip to main content
Community site session details

Community site session details

Session Id : FCXqyDv3XSvQUC7tBWnx+K
Power Automate - Building Flows
Unanswered

Flow to delete files in folder for SharePoint Document Library after X days

Like (0) ShareShare
ReportReport
Posted on 1 May 2018 13:48:37 by

I have a document library named documents and a folder in it called PDFs. In the PDFs folder, I have a bunch of PDFs. I want to be able to create a flow that will automatically delete the PDF files after 30-days. I have tried creating a flow but am unsuccessful. I am not sure how to limit it to the PDFs folder. Also, i can only get it to delete a single file that i choose and not multiple files in the folder. 

  • Community Power Platform Member Profile Picture
    on 02 May 2018 at 14:59:26
    Re: Flow to delete files in folder for SharePoint Document Library after X days

    Thanks for the reply. I actually did a test flow without the file age condition just to see if it would actually delete the files in the document library. Here is what the result was. I created a document library with this structure:

     

    Document Library/Test Folder 1/Test Folder 2

     

    This work fine and all the files delete as expected. Problem is, I have another document library name "Documents" and there are subfolders in there as well. When I use the same flow  that worked on the other document library and change the library location, none of the files delete. I have full control permissions on both dicument libraries. The strange thing is the filter array has an output, but it doesnt show the files

    that are in the document library (2 PDFs).

     Capture.PNG

     

     

  • v-xida-msft Profile Picture
    on 02 May 2018 at 06:04:54
    Re: Flow to delete files in folder for SharePoint Document Library after X days

    Hi @Anonymous,

     

    Could you please share a screenshot of your flow's configuration?

    Do you want to delete the files in your SharePoint library folder when they are 30 days old?

     

    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 "Get files (properties only)" action, specify Site Address and the Library Name set to Reporting. On your side, the Library Name set to documents.
    • Add a "Apply to each" action, input parameter set to output of "Get files (properties only)" action.
    • Within "Apply to each" action, add a condition, left input box set to Folder path dynamic content of the "Get files (properties only)" action, right input box set to Flow (On your side, right input box set to PDFs), within middle drop down, choose contains.

             Within "If/yes" branch of Condition, add a "Condition 2", click "Edit in advanced mode", type the following formula:

    @equals(formatDateTime(item()?['Created'], 'MM/dd/yyyy'), formatDateTime(addDays(utcNow(), -30), 'MM/dd/yyyy'))

    Within "If/yes" branch of Condition 2, add a "Delete file" action, specify Site Address and the File Identifier field set to Identifier dynamic content of the "Get files (properties only)" action.

     

    Image reference:18.JPG

     

    19.JPG

    The flow works successfully as below:20.JPG

     

     

    Best regards,

    Kris

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

Announcing our 2025 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for…

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!

Leaderboard > Power Automate

#1
Tomac Profile Picture

Tomac 986 Moderator

#2
stampcoin Profile Picture

stampcoin 699 Super User 2025 Season 2

#3
Riyaz_riz11 Profile Picture

Riyaz_riz11 577 Super User 2025 Season 2