Excluding all but a single subdirectory from a file search
<p>I have a directory structure that resembles the following:</p>

<pre><code>Dir1
Dir2
Dir3
Dir4
    L SubDir4.1
    L SubDir4.2
    L SubDir4.3
</code></pre>

<p>I want to generate a list of files (with full paths) that include all the contents of <code>Dirs1-3</code>, but only <code>SubDir4.2</code> inside <code>Dir4</code>. The code I have so far is</p>

<pre><code>import fnmatch
import os

for root, dirs, files in os.walk( '.' )
    if 'Dir4' in dirs:
        if not 'SubDir4.2' in 'Dir4':
            dirs.remove( 'Dir4' )
    for file in files
        print os.path.join( root, file )
</code></pre>

<p>My problem is that the part where I attempt to exclude any file that does not have <code>SubDir4.2</code> in it's path is excluding everything in <code>Dir4</code>, including the things I would like to remain. How should I amend that above to to do what I desire?</p>

<p><strong>Update 1</strong>: I should add that there are a lot of directories below <code>Dir4</code> so manually listing them in an excludes list isn't a practical option. I'd like to be able to specify <code>SubDur4.2</code> as the only subdirectory within <code>Dir4</code> to be read.</p>

<p><strong>Update 2</strong>: For reason outside of my control, I only have access to Python version 2.4.3.</p>
