Created
October 10, 2014 15:33
-
-
Save nicholastjohnson/5334bb3730eb90072a46 to your computer and use it in GitHub Desktop.
Python script to delete all files less than a certain size in a directory and subdirectories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os, os.path | |
for root, _, files in os.walk("C:/some/dir"): | |
for f in files: | |
fullpath = os.path.join(root, f) | |
try: | |
if os.path.getsize(fullpath) < 10 * 1024: #set file size in kb | |
print fullpath | |
os.remove(fullpath) | |
except WindowsError: | |
print "Error" + fullpath |
Thank you for posting this - very helpful.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice little Script, thanks. For Python3 brackets at the print statetements would come in handy.