Find files (but ignore them in certain folders)
<p>I want to find files of a specific type in a certain directory. The directory has lots and lots of subfolders and I want to ignore certain ones. I am using the following code-</p>

<pre><code>def locate(pattern, root=os.curdir):
    '''Locate all files matching supplied filename pattern in and below
    supplied root directory.'''
    for path, dirs, files in os.walk(os.path.abspath(root)):
        for filename in fnmatch.filter(files, pattern):
            yield os.path.join(path, filename)


for filename in locate("*.s2p"):
          #do something
</code></pre>

<p>I think there should be some way to change os.curdir to os.curdir (minus some folders) , or perhaps I can check current path and put in a conditional loop ? I tried os.cwd() but i got an error message saying 'module' object has no attribute 'cwd'</p>
