Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Calculate age of file with python
#!/usr/bin/env python
import datetime
import os
file_mod_time = datetime.datetime.fromtimestamp(os.path.getmtime('foobar.txt'))
today = datetime.datetime.today()
age = today - file_mod_time
if age.days > 90:
print "File older than 90 days"
else:
print "File not older than 90 days"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment