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?
Use glob.glob:
For learning purposes here my code, basically the same as from @Kevin Vincent though not as compact, but better to read and understand:
Assuming you have imported os and defined your path, this will work:
Give this guy a try: