Skip to content

Instantly share code, notes, and snippets.

@leveled
Created October 14, 2021 18:16
Show Gist options
  • Save leveled/bf029dc2491684bb005ad99f1e568ff8 to your computer and use it in GitHub Desktop.
Save leveled/bf029dc2491684bb005ad99f1e568ff8 to your computer and use it in GitHub Desktop.
Find most recently modified file in Python
import os
max_mtime = 0
for dirname,subdirs,files in os.walk("."):
for fname in files:
full_path = os.path.join(dirname, fname)
mtime = os.stat(full_path).st_mtime
if mtime > max_mtime:
max_mtime = mtime
max_dir = dirname
max_file = fname
print max_dir, max_file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment