def rglob(dirname, pattern, dirs=False, sort=True):
fns = []<EOL>path = str(dirname)<EOL>if os.path.isdir(path):<EOL><INDENT>fns = glob(os.path.join(escape(path), pattern))<EOL>dns = [fn for fn <EOL>in [os.path.join(path, fn)<EOL>for fn in os.listdir(path)] <EOL>if os.path.isdir(fn)]<EOL>if dirs==True:<EOL><INDENT>fns += dns<EOL><DEDENT>for d in dns:<EOL><INDENT>fns += rglob(d, pattern)<EOL><DEDENT>if sort==True:<EOL><INDENT>fns.sort()<EOL><DEDENT><DEDENT>else:<EOL><INDENT>log.warn("<STR_LIT>" % path)<EOL><DEDENT>return fns<EOL>
recursive glob, gets all files that match the pattern within the directory tree