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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Flow to delete files i...
Power Automate
Unanswered

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

(0) ShareShare
ReportReport
Posted on 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. 

Categories:
I have the same question (0)
  • v-xida-msft Profile Picture
    on at

    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

  • Community Power Platform Member Profile Picture
    on at

    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

     

     

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 503 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 321 Moderator

#3
abm abm Profile Picture

abm abm 237 Most Valuable Professional

Last 30 days Overall leaderboard