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 / How to delete all file...
Power Automate
Unanswered

How to delete all files in OneDrive created in the past 24 hours?

(0) ShareShare
ReportReport
Posted on by 17

Hi guys,

 

So I'm brand new to PA. Just discovered it yesterday. So I've been testing it and playing around with it to fully get a feel of all the flows by creating different ones myself rather than templates.

 

In the process, I have created a very cluttered OneDrive that I need to clear up.

 

How can I create a flow where it'll simply delete all files from my OneDrive that were created in the last day (or any time range for that matter)?

 

I have tried using the 'move/replace a file' action, but it won't let me select a folder, only a file? I don't just need to delete one file (don't need a flow for that anyway), I need to filter by time and delete. For that, I also need to be able to select dynamic content (which it's not letting me either). Does anybody know how to do that? 

 

Here's my (very bad) attempt at creating this flow lol. Would appreciate it if someone could help.

 

powerautomatist_0-1625326888432.png

 

Many thanks!

Categories:
I have the same question (0)
  • Verified answer
    ccc333ab Profile Picture
    1,144 on at

    Are all the files in a single folder...or are they all over the place? 

     

    If in a single folder, the easy way to do this is just to loop through each file and test if the file date is greater than or equal to today's date minus one. 

     

    So....

     

    1. Get all files in folder: 

    ccc333ab_0-1625333026765.png

    2. Loop through each value, and then check if the Last Modified Date is greater than or equal to today's date subtract one. 

    ccc333ab_1-1625333074819.png

     

    Expression on right side of condition is: 

    addDays(utcNow(), -1, 'yyyy-MM-dd')

     

    Note: I just have a COMPOSE statement in my YES response as I don't want to really delete any of my files, but this is where you would add in your delete....

     

  • powerautomatist Profile Picture
    17 on at

    .

  • powerautomatist Profile Picture
    17 on at

    Hi ccc333ab,

     

    Thank you so much for your help.

     

    I just tried this, and it ran successfully the first two times, but it didn't delete anything. Turns out I hadn't changed the condition to 'greater than'. I corrected it, then I got this. Not sure why.

     

    powerautomatist_0-1625403863609.png

     

     

    Do you think you could help? 

     

    Thanks

  • ccc333ab Profile Picture
    1,144 on at

    Sorry, but I cannot read the image you pasted, even if I enlarge it. Can you either type out what the message says or paste in a higher quality image. 

  • ccc333ab Profile Picture
    1,144 on at

    One thought.

     

    The Delete Item would throw an error if you are trying to delete any folders (as it only deletes files). And there is no "Delete Folder" currently in Power Automate.

  • powerautomatist Profile Picture
    17 on at

    Hi there,

     

    I know this reply is a long time coming, but I finally got around to it.

     

    Thank you for your reply, I did try the flow again. It ran successfully the second time, except nothing got deleted. Not sure why.

     

    Since it's been a while, I now need a flow where I can specify a date range that I'd like to delete files from. Do you think that's an option? 

  • Verified answer
    ccc333ab Profile Picture
    1,144 on at

    Solution for date range, pretty much following the same logic as the original solution: 

     

    1. Setup your trigger to allow you to enter in your date range you want to use. 

    ccc333ab_0-1627245847086.png

     

    2. Get your list of files as per before.

    ccc333ab_1-1627245877621.png

     

    3. Now loop through the files, and check to see if the date last modified is greater than or equal to your start date, AND if the date last modified is less than or equal to your end date.  (Note: I always format my dates just to make sure they are of the same format just in case...). 

    IF TRUE---> Then delete that file (using the ID of the current item) 

    ccc333ab_3-1627246045936.png

     

    The expressions in the Condition are: 

    formatDateTime(items('Apply_to_each')?['LastModified'],'yyyy-MM-dd')
     is greater than or equal to
    formatDateTime(triggerBody()['date'],'yyyy-MM-dd')
    
    
    formatDateTime(items('Apply_to_each')?['LastModified'],'yyyy-MM-dd')
     is less than or equal to
    formatDateTime(triggerBody()['date_1'],'yyyy-MM-dd')

    Note: Where it says date and date_1 was named by the system when I created the two inputs. Make sure your values are the same (depending on if you have other inputs in your trigger). 

     

  • powerautomatist Profile Picture
    17 on at

    Wow, you, sir, are a hero!

     

    Thank you so much! I really appreciate your helpful responses, this is going to make my life much easier knowing these flows.

     

    Thanks once again, and have a brilliant weekend! 🙂 

  • prawincumar Profile Picture
    on at

    How do I delete all files from the folder that I have selected?

  • ccc333ab Profile Picture
    1,144 on at

    @prawincumar Loop through the folder you selected (with Apply to Each), and in that loop, use a "Delete File" for each ID. So something like the following. 

     

    ccc333ab_0-1705515406538.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 538 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 405 Moderator

#3
abm abm Profile Picture

abm abm 252 Most Valuable Professional

Last 30 days Overall leaderboard