Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """Sorts dir from newest to oldest and returns list, access files by index"""
- import os
- import glob
- files_path = os.path.join('path to folder', '*.csv') # change file extension to suit
- files = sorted(glob.iglob(files_path), key=os.path.getctime, reverse=True) # sorts files from newest to oldest
- newest_file = files[0] # newest .csv file, can use index to access file
- second_newest_file = files[1] # example
- oldest_file files[-1] example
Advertisement
Add Comment
Please, Sign In to add comment