I suggest you use glob instead.
As the help on glob says:
glob(pathname) Return a list of paths matching a pathname pattern. The pattern may contain simple shell-style wildcards a la fnmatch. However, unlike fnmatch, filenames starting with a dot are special cases that are not matched by '*' and '?' patterns.
So your template is every first level directory, which I think would be something like this:
/root_path/*/sub_folder1/sub_folder2
So, you start from your root, get everything on this first level, and then look for sub_folder1/sub_folder2 . I think it works.
Combine all of this:
from glob import glob dirs = glob('/root_path/*/sub_folder1/sub_folder2')
idjaw
source share