I'm trying to delete files from a folder where the date modified is greater than 3 days.
numdays = 86400 * 3 # Seconds in a day times 3 days
from datetime import datetime
a = datetime.now()
for delete_f in os.listdir(src1):
file_path = os.path.join(src1, delete_f)
try:
if (a - datetime.fromtimestamp(os.path.getmtime(file_path)) > numdays):
os.unlink(file_path)
except Exception as e:
print (e)
I get the error unorderable types: datetime.timedelta() > int()
I'm not really sure how to go about getting the numdays part, anyone have suggestions? TIA