I created a python script for cleaning old files on a windows disk. Now I want to improve that script and check if I went over a predefined disk usage and then delete files ... how I can do it? Here's my code:
import os, time
path = r"f:\backup"
now = time.time()
for f in os.listdir(path):
if os.stat(f).st_mtime < now - 180 * 86400:
if os.path.isfile(f):
os.remove(os.path.join(path, f))
I need it because I've configured a backup of my computer on external disk and sometimes it can't do the backup because disk is full.