I need to remove files that are older than 14 days from a directory that stores our backups. I can get the time of an individual file by using something like this:
start = (os.path.getmtime(join(dirpath, name))/3600*24)
But I'm getting confused with how I use timedelta to find the difference between this and the current date.
I'd like to use something like this:
d = (datetime.timedelta(time.now() - os.path.getmtime(join(dirpath, dirname))
but I'm just not getting it. I'm on my own here, and I'd love some help.
Try:
if time.time() - os.path.getmtime(filename) > 14 * 24 * 3600:
print 'the file is older than 14 days'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With