Python: Find newest file with .MP3 extension in directory
I am trying to find the most recently modified (From here on out 'newest') file of a specific type in Python. I can currently get the newest, but it doesn't matter what type. I would like to only get the newest MP3 file.
Currently I have:
import os newest = max(os.listdir('.'), key = os.path.getctime) print newest
Is there a way to modify this to only give me only the newest MP3 file?
import os import glob newest = max(glob.iglob('*.[Mm][Pp]3'), key=os.path.getctime)