Python - Select latest file with a specific start string and extension
<p>Newbie: I have the following code that fetches the latest Excel file from the downloads folder, based on the Modification time:</p>

<pre><code>import os
import glob
latest_Excel = max(glob.iglob('C:\Users\Aditya\Downloads/*.xlsx'), key=os.path.getmtime)
</code></pre>

<p>Now, all excel files have either <strong>'Local'</strong> or <strong>'Global'</strong> as their start name. </p>

<p>For eg.
Local_20160808.xlsx,
Local_20160809.xlsx,
Global_20160810.xlsx,
Global_20160811.xlsx, etc</p>

<p>So, how can we get the names of 2 files:
the latest Excel file with 'Local' as the start name and the latest Excel file with 'Global' as the start name, from the same folder?</p>

<p>Thanks</p>

<pre><code>latest_local_Excel = max(glob.iglob('C:\Users\Aditya\Downloads/Local*.xlsx'),
                         key=os.path.getmtime)
latest_gloabl_Excel = max(glob.iglob('C:\Users\Aditya\Downloads/Global*.xlsx'),
                          key=os.path.getmtime)
</code></pre>

python excel