Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from pathlib import Path # (glob import not required)
- # can replace max for min for oldest file
- def latest_file(dir_path: str, file_ext=".csv") -> Path:
- """returns most recent file
- arg 1: dir path, arg 2: file ext (default .csv)"""
- str_path = Path(dir_path).glob(f"*{file_ext}")
- latest_file = max(str_path, key=lambda item: item.stat().st_ctime)
- return latest_file
Add Comment
Please, Sign In to add comment