Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A script that deletes file that a smaller than a defined size.
import os
# File path (Do not forget the "/" at the end of the path.)
path = 'E:/test/'
# File size in kb. Files smaller than x kb are deleted.
filesize = 1
files = os.listdir(path)
for f in files:
file_stats = os.stat(path + f)
if os.path.exists(path + f) and file_stats.st_size < filesize*1024:
os.remove(path + f)
print(f + "\t" + str(file_stats.st_size / 1024) + "kb \t file deleted")
print(f + "\t" + str(file_stats.st_size / 1024) + "kb")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment