How to find newest file with .MP3 extension in directory?
file-io, python
Solution
Use glob.glob:
import os
import glob
newest = max(glob.iglob('*.[Mm][Pp]3'), key=os.path.getctime)
Problem
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?