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
Post a Comment