How to sort the files based on the date?

Madhavan Bomidi blmadhavan at gmail.com
Mon Jul 15 04:09:55 EDT 2019


Thanks Peter. 

The following lines worked:

import glob
import datetime 

def get_datetime (filename):
    parts = filename.split ("_")
    return datetime.datetime.strptime (parts[1] + parts[2], "%d%b%Y%H%M") 

filenames = sorted(glob.glob('3RIMG _ *. h5'), key = get_datetime) 




More information about the Python-list mailing list