Skip to content

Instantly share code, notes, and snippets.

@rsperl
Last active July 25, 2022 15:51
Show Gist options
  • Select an option

  • Save rsperl/89bf06e72a8c72bdcac5d846fb7c6cbd to your computer and use it in GitHub Desktop.

Select an option

Save rsperl/89bf06e72a8c72bdcac5d846fb7c6cbd to your computer and use it in GitHub Desktop.
get the latest file/directory #python #snippet
#!/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