import os, glob import datetime as dt def makeday(text): return dt.datetime.strptime(text, "%Y-%m-%d").date() def delete_obsolete_slides(filespec, day) """delete old files Args: filespec (string): directory path and filespec, ex: /tmp/*.pdf day (datetime.date): any files older than this date match """ for fn in glob.glob(filespec): stamp = dt.datetime.fromtimestamp(os.path.getmtime(fn)).date() if stamp < day: os.remove(fn) """ I love the langeage From the datetime library using the datetime object can call the fromtimestamp function to convert a timestamp into a date-time value and then truncate that date-time value to a date value """ # Example Run: threshhold = makeday('2017-02-15') delete_obsolete_slides('/tmp/*.png", threshhold)