As soon as you come across **, you will have to rewrite the entire directory structure, so I think that at this moment the easiest method is to iterate through the directory using os.walk, build the path, and then check if it matches the pattern. You can probably convert to regex, for example:
def glob_to_regex(pat, dirsep=os.sep):
dirsep = re.escape(dirsep)
print re.escape(pat)
regex = (re.escape(pat).replace("\\*\\*"+dirsep,".*")
.replace("\\*\\*",".*")
.replace("\\*","[^%s]*" % dirsep)
.replace("\\?","[^%s]" % dirsep))
return re.compile(regex+"$")
( , , [a-z], , , ). ( \*\*/ , \*\*/CVS ./CVS, \*\* .)
, , , **, , . , , , , , :
. .. pat.split('/') -> ['**','CVS','*']
. . n levels deep -> look at pat[n].
pat[n] == '**' :
dirsep.join(pat[n:])glob\_to\_regex()os.walk , , . , .
pat "**", , /dirs, glob.glob(os.path.join(curpath,pat[n]))
pat "**", , , ( glob) pat[n]. , , ( pat[n+1])