cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
yoshihirok
Level 10

Tips: Delete files older than 7 days at every day

I want to share my Flow for delete files older than 7 day.

 

My Scenario:

Clear old files from my servers.

Old files mean that last update datetime  more than 7 days ago.

for keep free storage space in my drive.

 

 

1.png

 

 

 

 

My Flow:

1. Trigger: Scedule - Recurrence ( Freaquency = Day, Interval = 1)

2. Action: File Systems - List files in folder ( Folder = <your target folder> )

3. Apply to each

  3-1. Action: Data Operations - Compose ( Inputs = "@div(sub(ticks(utcnow()), ticks(item()?['LastModified'])), 864000000000)" )

  3-2. Condition: ( Compose - Outputs , is greater than, 7 )

    IF YES:

      3-2-1. Action: File Systems - Delete file ( File = Path )

      3-2-2. Action: Microsoft Teams - Post message ( Message = Delete Name )

 

Comment 3-1 : Need double quote for Inputs.

Comment 3-1 : Calcurate days from last updated.

Comment 3-2 : Outputs from 3-1 Compose.

Comment 3-2-1 : Path from Step 2 List files in folder.

Comment 3-2-2 : Name from Step 2 List files in folder.

 

Regards,

Yoshihiro Kawabata

 

 

 

6 REPLIES 6
Community Support Team
Community Support Team

Re: Tips: Delete files older than 7 days at every day

@yoshihirok,

 

Thanks for sharing.

Please also submit this into Flow template, Which I think should be helpful for the others to use as an example.

 

Regards,

Michael

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
WECILHans
Level: Power Up

Re: Tips: Delete files older than 7 days at every day

Thanks for this. I have a situation where I need to delete all folders within a parent folder on a regular basis. Will this Flow do that, or can you recommend how?

Thanks

Hans

yoshihirok
Level 10

Re: Tips: Delete files older than 7 days at every day

Hi, @WECILHans

 

To do 'all folders within a parenet folder', I use the List for folders.

 

Regards,

Yoshihiro Kawabata

WECILHans
Level: Power Up

Re: Tips: Delete files older than 7 days at every day

Thanks Yoshihiro,

I shall give this a go next week!

Hans

Administrator
Administrator

Re: Tips: Delete files older than 7 days at every day

Hello, @WECILHans!

 

Thank you for posting to the Microsoft Flow Community forums! I see that in one of the above replies you were offered a solution to your issue! If you feel that the reply offered an applicable and satisfactory solution, please click "Accept as Solution" so that other users can find this information and utilize it easily!

 

 

Thank You!

-Gabriel

Flow Community Manager

-Gabriel
Microsoft Power Automate Community Manager
Are YOU a member of your local Power Automate User Group?
Fill out This Form to claim your Community User Group Member Badge!
adunn
Level: Power Up

Re: Tips: Delete files older than 7 days at every day

Hi,

I have tried to copy this functionality for items in a Sharepoint list. When I run the flow, it runs into an error during the "Condition" section, as it claims that the Output from the Compose function is a string that can't be compared to the number I have put there.

Is there any reason the Input you create in Compose would produce a String value for a Sharepoint list where it wouldn't for a File? Do I need to do something different for a Sharepoint List item that you are aware of?

Thanks.

Helpful resources

Announcements
firstImage

New & Improved Power Automate Community Cookbook

We've updated and improved the layout and uploading format of the Power Automate Cookbook!

thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

firstImage

Incoming: New and improved badges!

We've given our badges an overhaul and also added some brand new ones!

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

sixthImage

Power Platform World Tour

Find out where you can attend!

seventhimage

Webinars & Video Gallery

Watch & learn from the Power Automate Community Video Gallery!

Top Kudoed Authors (Last 30 Days)
Users online (3,661)