determine directories with wildcard

Simon Brunning simon.brunning at
Tue Mar 8 14:54:26 CET 2005

On Tue, 8 Mar 2005 14:33:59 +0100, Thomas Rademacher
<rademacher at> wrote:
> Hello,
> I want to collect with the wildcard '*' all existing directories.
> For example:  /dir/dir/*/dir/*/dir/* or C:\dir\dir\*\dir\*\dir\*

How about something like:

import fnmatch
import os

root = 'd:\\'
filter = r'*\*python*\*'

for dirpath, dirnames, filenames in os.walk(root):
    if fnmatch.fnmatch(dirpath, filter):
        print 'matched', dirpath

Simon B,
simon at,

More information about the Python-list mailing list