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 / Delete files in folder...
Power Automate
Unanswered

Delete files in folder based on file size using desktop version

(1) ShareShare
ReportReport
Posted on by
Using the desktop version of power automate, i have created a flow that gets files from a folder on my C drive which contains all different file types, i am struggling to set up an action that deletes files where the file size if less than 18kb.
I have set up a for each loop and in the Get Files from folder filter, set the filter to the wildcard character of *. With a given variable called "AllFiles"
I then inserted the Get temporary file and have the variable "FileSize" where i can see within that the .size part of the file. I then used an If condition that is currently set to "=If FileSize.Size < 18432" then Delete File in "AllFiles".
I finish the If part of the loop and directly after it's "End" i have a Delete "FileSize" 
 
I need to leave files greater than 18kb in the same location.
 
I'm aware that the flow i have created might be a bit rough (see attached) as i am attempting so many different ways, i have just stripped it back to where i am upto right now.
When run it leaves all the files untouched, what am i missing?
 
Thanks
Paul
Categories:
I have the same question (0)
  • Pstork1 Profile Picture
    68,717 Most Valuable Professional on at
    Deleting files in a loop that points to the files themselves is normally an issue since the loop will change once you delete an existing file.  The typical workaround is to split it into two loops.  One to check the filesize and add the name/path of the files you want to delete to a list. Then a second loop that runs through that list and uses the name/path of each file to delete it. The file gets deleted, but not the entry in the list so the loop doesn't change size.

    ----------------------------------------------------------------------------------
    If this Post helped you, please click "Does this answer your question" and give it a like to help others in the community find the answer too!

    Paul Papanek Stork, MVP
    Blog: https://www.dontpapanic.com/blog
     

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 501 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 323 Moderator

#3
abm abm Profile Picture

abm abm 237 Most Valuable Professional

Last 30 days Overall leaderboard