title: Python get most recent file in a directory with certain extension
body: <p>I'm trying to use the newest file in the 'upload' directory with '.log' extension to be processed by Python. I use a <code>Ubuntu</code> web server and file upload is done by a html script. The uploaded file is processed by a Python script and results are written to a <code>MySQL</code> database. I used <a href="https://stackoverflow.com/questions/18279063/python-find-newest-file-with-mp3-extension-in-directory">this</a> answer for my code.</p>
  
  <pre><code>import glob
  newest = max(glob.iglob('upload/*.log'), key=os.path.getctime)
  print newest
  f = open(newest,'r')
  </code></pre>
  
  <p>But this is not getting the newest file in the directory, instead it gets the oldest one. Why?</p>