def listFiles(root, patterns='<STR_LIT:*>', recurse=<NUM_LIT:1>, return_folders=<NUM_LIT:0>):
import os.path, fnmatch<EOL>pattern_list = patterns.split('<STR_LIT:;>')<EOL>class Bunch:<EOL><INDENT>def __init__(self, **kwds): self.__dict__.update(kwds)<EOL><DEDENT>arg = Bunch(recurse=recurse, pattern_list=pattern_list,<EOL>return_folders=return_folders, results=[])<EOL>def visit(arg, dirname, files):<EOL><INDENT>for name in files:<EOL><INDENT>fullname = os.path.normpath(os.path.join(dirname, name))<EOL>if arg.return_folders or os.path.isfile(fullname):<EOL><INDENT>for pattern in arg.pattern_list:<EOL><INDENT>if fnmatch.fnmatch(name, pattern):<EOL><INDENT>arg.results.append(fullname)<EOL>break<EOL><DEDENT><DEDENT><DEDENT><DEDENT>if not arg.recurse: files[:]=[]<EOL><DEDENT>os.path.walk(root, visit, arg)<EOL>return arg.results<EOL>
Recursively list files

from Parmar and Martelli in the Python Cookbook