Python get most recent file in a directory with certain extension -


i'm trying use newest file in 'upload' directory '.log' extension processed python. use ubuntu web server , file upload done html script. uploaded file processed python script , results written mysql database. used this answer code.

import glob newest = max(glob.iglob('upload/*.log'), key=os.path.getctime) print newest f = open(newest,'r') 

but not getting newest file in directory, instead gets oldest one. why?

the problem logical inverse of max min:

newest = max(glob.iglob('upload/*.log'), key=os.path.getctime) 

for purposes should be:

 newest = min(glob.iglob('upload/*.log'), key=os.path.getctime) 

Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -