title: Getting the latest file name etc using glob.glob & max (os.path.getctime)
body: <p>I am trying to get the file name of the latest file on a directory which has couple hundred files on a network drive. </p>
  
  <p>Basically the idea is to snip the file name (its the date/time the file was downloaded, eg <code>xyz201912191455.csv</code>) and paste it on a <code>config file</code> every time the script is run.</p>
  
  <p>Now the <code>list_of_files</code> usually run in about a second but <code>latest_file</code> takes about 100 seconds which is extremely slow. </p>
  
  <p>Is there a faster way to extract the information about the latest file?</p>
  
  <p>The code sample as below:</p>
  
  <pre><code>import os
  import glob
  import time
  from configparser import ConfigParser
  import configparser
  list_of_files = glob.glob('filepath\*', recursive=True)
  latest_file = max(list_of_files, key=os.path.getctime)
  
  list_of_files2 = glob.glob('filepath\*', recursive=True)
  latest_file2 = max(list_of_files2, key=os.path.getctime)
  </code></pre>