Last active
July 25, 2022 15:51
-
-
Save rsperl/89bf06e72a8c72bdcac5d846fb7c6cbd to your computer and use it in GitHub Desktop.
get the latest file/directory #python #snippet
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
| #!/usr/bin/env python3 | |
| import os | |
| def get_newest(src_dir: str) -> str: | |
| """return the newest file or directory""" | |
| full_path = [src_dir + "/" + item for item in os.listdir(src_dir)] | |
| oldest = max(full_path, key=os.path.getctime) | |
| return os.path.basename(oldest) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment