This script will print the n number of biggest files in the specified dir and it's sub dir. It will be helpful when you want to free up some space in HD
import os,constants import math from collections import Counter LOCATION=constants.DOWNLOAD_PATH LIST_NUMBER_OF_FILES=25 FILE_SIZE=6250000 #Approx 50 MB def convert_size(size_bytes): if size_bytes == 0: return "0B" size_name = ("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB") i = int(math.floor(math.log(size_bytes, 1024))) p = math.pow(1024, i) s = round(size_bytes / p, 2) return "%s %s" % (s, size_name[i]) files=[val for sublist in [[os.path.join(i, j) for j in i] for i in os.walk(LOCATION)] for val in sublist] files=list(filter(lambda x: os.stat(x).st_size >FILE_SIZE,files)) c = Counter() for f in files: c[f]=os.stat(f).st_size for item in (sorted(c.items(), key=lambda i: i, reverse=True)[:]): print(os.path.split(item)," - ",convert_size(item))
Please Visit my Git Repo to check out all the previous day challenges.
Little bits of appreciation can make _big_ differences in maintainers' lives. Here's one way you can show appreciation that should take less than five minutes out of your day and just might make someone else's. 🙌