Showing results for 
Search instead for 
Did you mean: 
Regular Visitor

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

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 Support
Community Support

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

Hi @rmath,


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



The flow works successfully as below:20.JPG



Best regards,


Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Regular Visitor

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).




Helpful resources

Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

Tech Marathon

Maratón de Soluciones de Negocio Microsoft

Una semana de contenido con +100 sesiones educativas, consultorios, +10 workshops Premium, Hackaton, EXPO, Networking Hall y mucho más!

Top Solution Authors
Top Kudoed Authors
Users online (6,525)