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

C# random value from dictionary and tuple -

cgi - How do I interpret URLs without extension as files rather than missing directories in nginx? -

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