osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to sort the files based on the date?


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)