2 ms·
More idiomatic version is more readable but also more verbose: cutoff_date = datetime.now() - timedelta(days=7) for basepath,_,files in os.walk('/tmp')
by zokier 11y ago
More idiomatic version is more readable but also more verbose:
cutoff_date = datetime.now() - timedelta(days=7)
for basepath,_,files in os.walk('/tmp'):
for filename in files:
filepath = os.path.join(basepath, filename)
if datetime.fromtimestamp(os.stat(filepath).st_mtime) < cutoff_date:
os.unlink(filepath)
Python is not really that great when forced to oneliner format, and I'm not really a good code golfer anyways.