get the latest file in a directory

Gustavo Niemeyer niemeyer at conectiva.com
Wed Oct 29 16:46:25 EST 2003


> I was wondering what is a quick way to find the latest(last modified
> date) file from a directory.

 >>> l = [(os.path.getmtime(x), x) for x in os.listdir(".")]
 >>> l.sort()
 >>> l[-1]
 (1067457449, '.svn')

-- 
Gustavo Niemeyer
http://niemeyer.net





More information about the Python-list mailing list