Created
October 14, 2021 18:16
-
-
Save leveled/bf029dc2491684bb005ad99f1e568ff8 to your computer and use it in GitHub Desktop.
Find most recently modified file in Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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