How to use Python to search for file by name, find the latest modified, find next file and repeat steps?
<p>I have a folder that has many DWG files and an example of some files might be</p>

<pre><code>LINCOLN 09-17 #1-29H ASBUILT 10-26-2010.dwg
LINCOLN 09-17 #1-29H FINAL 01-20-2011.dwg
CAMPBELL 07-17 #5-29H DRAFT 01-20-2011.dwg
CAMPBELL 07-17 #5-29H FINAL 01-27-2011.dwg
CAMPBELL 07-17 #5-29H FINAL 01-27-2011_1.dwg
</code></pre>

<p>I would need to capture (maybe in a list?) only the dwg files that have FINAL and are the latest modified dwg file for that file name.  So the files above that would be captured are</p>

<pre><code>LINCOLN 09-17 #1-29 FINAL 01-20-2011.dwg
CAMPBELL 07-17 #5-29H FINAL 01-27-2011_1.dwg
</code></pre>

<p>Any suggestions?</p>

<p>Moderator, I cannot seem to add comments to the questions below.  Why is that??</p>

<p>Here is what I have so far..  I placed comments where I think I need changes</p>

<pre><code>import os 

rootdir='c:\Your\Path'

for subdir, dirs, files in os.walk(rootdir):    
    for file in files:

    # I need to check only files with the same name so I can 
    # get the latest of those files before checking next files      

        if os.path.getmtime(file):
            # I believe this will get time file was modified but
            # but how do I store this to compare to other files
            # with this name??
</code></pre>
