Home | My New Hugo Project

Python - how to get the lastest file of glob by date

2022-03-05

  1.  Use Sorted with a key for getmtime
  2. pop off the last one and that is your file
import os,glob

my_xlsm = sorted(glob.glob(r"C:\Users\jibsheet\Downloads\Sample*.xlsm"), key=os.path.getmtime )

latest_xlsm = my_xlsm.pop()