So I'm trying to write a script that allows me import the most recently modified file from a directory. I've looked at the glob
and os.listdir
commands but they don't seem to do it (I get errors). Any thoughts?
import os
import glob
newest = max(glob.iglob('Directory Name'), key=os.path.getctime)
print newest
f = open(newest,'r')
I get an error:
max() arg is an empty sequence
Would something like os.stat work better?