determine directories with wildcard
Diez B. Roggisch
deetsNOSPAM at web.de
Tue Mar 8 08:43:16 EST 2005
Thomas Rademacher 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 can I resolve this problem?
This is some sort of pattern matching. What I'd do is to convert your
pattern to a regex:
rex = re.compile(r"/dir/dir/.*/dir/.*/dir/.*")
Then create a list of dirs with os.walk:
dirs = [dirpath for dirpath, foo, bar in os.walk(topdir) if
rex.match(dirpath)]
This is untested, but should do the trick.
--
Regards,
Diez B. Roggisch
More information about the Python-list
mailing list