Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Automate - Using Flows
Answered

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

(0) ShareShare
ReportReport
Posted on by

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.

  • JP21 Profile Picture
    9 on at
    Re: flow that delete files that are in a folder in a library sharepoint older than 2 days

    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

  • Community Power Platform Member Profile Picture
    on at
    Re: flow that delete files that are in a folder in a library sharepoint older than 2 days

    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!

  • ScottShearer Profile Picture
    25,208 Most Valuable Professional on at
    Re: flow that delete files that are in a folder in a library sharepoint older than 2 days

    @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
    on at
    Re: flow that delete files that are in a folder in a library sharepoint older than 2 days

    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?

     

  • Verified answer
    v-xida-msft Profile Picture
    on at
    Re: flow that delete files that are in a folder in a library sharepoint older than 2 days

    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

  • ScottShearer Profile Picture
    25,208 Most Valuable Professional on at
    Re: flow that delete files that are in a folder in a library sharepoint older than 2 days

    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

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,524 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 65,906 Most Valuable Professional

Leaderboard

Featured topics

Restore a deleted flow