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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / flow that delete files...
Power Automate
Answered

flow that delete files that are in a folder in a library sharepoint older than 2 days

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi,

 

I would like to know how to delete all file that is in a folder in a library sharepoint, that are older than two days.

 

i've seeing a some flow on this user community but none of them is what I need...

 

--------------------------------------------------

 

exemple:

 

all the files that in the library Reporting in the folder Flow ( Reporting/Flow/ ) that are older than 2 days has to be delete everyday.

 

-----------------------------------------------------

 

So first, I now i have to put a recurrence of 1 day.

 

Second, If I'm correct i have to have the sahrepoint "Get files (properties only) ".

 

Third, i think i should have "Apply to each", the output has to be "Value" of the "Get Files"

 

but after that i don't know.

Categories:
I have the same question (0)
  • ScottShearer Profile Picture
    25,290 Most Valuable Professional on at

    Here is a simple example that I believe will work for you.  I set the time to 2 minutes vs 2 days so it would be easier to test.  My If statement looks for the folder name in the path  - with a little work you can do better than that.

     

    I am filtering the Get File Properties with the following expression:  Created lt ' [Past Time]'  where Past Time is a reference to the output of the Get Past Time action.

     

    DelFiles.jpg

  • Verified answer
    v-xida-msft Profile Picture
    Microsoft Employee on at

    Hi @Anonymous,

     

    Do you want to delete all files which are older than 2 days within a folder of your SharePoint library?

     

    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 Library Name set to Reporting.
    • Add a "Filter array" action, From set to output of "Get files (properties only)" action. Click "Edit in advanced mode", type the following formula:
    @equals(item()?['{Path}'], 'Reporting/Flow/')
    • Add a "Apply to each", input parameter set to output of "Filter array" action.
    • Within "Apply to each" action, add a Condition, click "Edit in advanced mode", type the following formula:
    @less(formatDateTime(addDays(item()?['Created'], 2), 'MM/dd/yyyy'), utcNow('MM/dd/yyyy'))

    Within "If/yes" branch of Condition, add a "Delete file" action, specify Site Address and the File Identifier field set to following formula:

    item()?['{Identifier}']

    Image reference:20.JPG

     

    21.JPG

    The flow works successfully as below:22.JPG

     

     

    Best regards,

    Kris

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    I'm in the same boat but trying to find and delete all files that are older than 2 hours.

     

    After going through about 15 examples I still can't get it to work. Very simple flow in my head but the syntax is a bit infuriating (makes powershell feel good). 

     

    Recurrence every 2 hours.

    Get files (properties only). Only on the main Documents folder on the site. Single site.

    foreach value; condition is where I hit a wall. Trying to do a utcnow(); greater than addminutes 120 but none of the syntax I can find works right. 

    Yes delete file 'identifier'. 

     

    Really not sure how created date and all of that doesn't get pulled into these but I guess reasons.

     

    Any ideas?

     

  • ScottShearer Profile Picture
    25,290 Most Valuable Professional on at

    @Anonymous :

     

    I have a couple of suggestions.

    First, I suggest that you create a new post under a new topic with your question along with a screen shot of your current Flow.  This will make it much easier to assist.

     

    In addition, as I suggested above, you are much better off using an OData Filter in the Get Files (properties only) action.  Looping through every file is inefficient and, depending on the number of files and your license, may not return all files due to Flow limits.  In addition, you can only loop through a maximum of 5000 items unless you have a P2 license.

     

    In your new post, can you explain your criteria a little more?  Are you looking for files created within the last 2 hours?

     

    Scott

     

     

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hey Scott,

     

    Yeah I played with the OD field a little but couldn't come up with what magical code it was asking for.

     

    I did finally get the foreach loop to work by playing around with the time syntax. I saw there was a 'created' tag so that wouldv'e been real fun if MS just allowed created gt/lt whatever 'time' but I guess they've started making things more difficult in recent years instead of easier. 

     

    Oh well. Luckily this is a very infrequent used share so if it ever get's up to more than 10-15 files in it we've got a big issue. 🙂

     

    Thanks!

  • JP21 Profile Picture
    9 on at

    Hello,

    I have a slightly different task, I need the flow to identify files within folders that are in WI library, and then if those are older than a year (based on modified date) I need them to move to a diff library WI expired, but the folders stay in WI, only files are moving.

    I don´t want the folders to be considered in the flow (to be checked if they are older than a year) and then if the files are not older, nothing happens.

    Thank you

     

    JP21

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Automate

#1
Haque Profile Picture

Haque 283

#2
David_MA Profile Picture

David_MA 256 Super User 2026 Season 1

#3
Expiscornovus Profile Picture

Expiscornovus 225 Most Valuable Professional

Last 30 days Overall leaderboard