Skip to content

Instantly share code, notes, and snippets.

@andrewspiers
Last active August 29, 2015 14:00
Show Gist options
  • Save andrewspiers/901941302a0759c16fd4 to your computer and use it in GitHub Desktop.
Save andrewspiers/901941302a0759c16fd4 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import os
import sys
import time
purpose = "Print the age of a file rounded to the nearest second.\n"
usage = "Usage: " + sys.argv[0] + " <FILENAME>\n"
def fileage(f):
return int(round(time.time() - os.stat(f).st_mtime))
if __name__ == "__main__":
try:
print (fileage(sys.argv[1]))
except IndexError:
sys.stderr.write(purpose + "\n" + usage)
sys.exit(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment