title: Return List of Latest .tar Files as found in File Name Python
body: <p>I have various tar files in a folder "supertar", labeled as:-</p>
  
  <pre><code>esarchive--Mona-AB-Test226-8037affd-06d1-4c61-a91f-816ec9cb825f-05222017-4.tar,
  esarchive--Jackson-HQ-112-ecb5ab6a-c199-402d-9a8a-8c54c8901d66-06092017-4.tar,
  esarchive--Mona-AB-Test226-8037affd-06d1-4c61-a91f-816ec9cb825f-05202017-4.tar,
  esarchive--Jackson-HQ-112-ecb5ab6a-c199-402d-9a8a-8c54c8901d66-06012017-4.tar,
  esarchive--Jonah-7fbbbc6c-8463-4ec1-9bde-3fc5429311e5-06092017-4
  </code></pre>
  
  <p>How do I extract the latest .tar file name for each customer, such as Mona, Jackson, Jonah mentioned in their respective filename as per their date values (At the end in the File Name) so that I get a variable with values:</p>
  
  <pre><code>esarchive--Mona-AB-Test226-8037affd-06d1-4c61-a91f-816ec9cb825f-05222017-4.tar,
  esarchive--Jackson-HQ-112-ecb5ab6a-c199-402d-9a8a-8c54c8901d66-06092017-4.tar,
  esarchive--Jonah-7fbbbc6c-8463-4ec1-9bde-3fc5429311e5-06092017-4
  </code></pre>
  
  <p>I have executed the following code so far:-</p>
  
  <pre><code>    for file in glob.glob("*.tar"):
     # print "The File Being Untarred is:",file
      file_date_str = file.split('-')[-2]
      datetime_obj = datetime.datetime.strptime(file_date_str, '%m%d%Y')
      a=re.match("esarchive--(\w+)-(\w+)-(\w+)", file).group(1)# Gets Mona from file name
      b=re.match("esarchive--(\w+)-(\w+)-(\w+)", file).group(2)# Gets AB from file name
      c=re.match("esarchive--(\w+)-(\w+)-(\w+)", file).group(3)# Gets Test226 from file name
      s = a+'-'+b+'-'+c
      d=s.lower()
      my_dict={}
      date = datetime.date.today()
      print(s)
      try:
          (latest_date, _) = my_dict['name'] # _ has file name, which you don't want to compare.
          if date &gt; latest_date:
          # If entry for this name exists,
          # Replace the info with latest date.
             my_dict['name'] = (date,file)
      except KeyError:
      # No info for this name in dictionary.
             my_dict['name'] = (date,file)
  
      print "The File Being Untarred is:",my_dict['name']
      tar = tarfile.open("/home/chetan/Desktop/supertar/"+my_dict['name'][1]) 
      tar.extractall(path="/home/chetan/Documents/chetan-dump-es") # untar file into same directory
      tar.close()
  </code></pre>
  
  <p>I am getting a list of all files instead of only the latest ones.</p>