Skip to content

Instantly share code, notes, and snippets.

@vadimii
Last active January 1, 2016 09:39
Show Gist options
  • Save vadimii/8126354 to your computer and use it in GitHub Desktop.
Save vadimii/8126354 to your computer and use it in GitHub Desktop.
Min-Max file dates in directory
import os, sys, datetime
maxm = minm = None
for root, dirs, files in os.walk(sys.argv[1] if len(sys.argv) > 1 else '.'):
for name in files:
path = os.path.join(root, name)
mtime = os.path.getmtime(path)
maxm = maxm if maxm and maxm > mtime else mtime
minm = minm if minm and minm < mtime else mtime
def ftime(secs):
return datetime.datetime.fromtimestamp(secs).strftime('%Y-%m-%d')
print ftime(minm), ftime(maxm)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment