Skip to content

Instantly share code, notes, and snippets.

@laserson
Created September 14, 2013 21:48
Show Gist options
  • Select an option

  • Save laserson/6565965 to your computer and use it in GitHub Desktop.

Select an option

Save laserson/6565965 to your computer and use it in GitHub Desktop.
Find the most recently modified file in the current directory.
#! /usr/bin/env python
import os
import time
times = []
for tup in os.walk('.'):
for f in tup[2]:
if f.strip() == '.DS_Store':
continue
path = os.path.join(tup[0], f)
s = os.stat(path)
times.append((path, s.st_mtime))
result = max(times, key=lambda x: x[1])
print result[0]
print time.ctime(result[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment