def listFiles(root, patterns=u'*', recurse=1, return_folders=0):
 import os.path
 import fnmatch
 pattern_list = patterns.split(u';')
 results = []
 for (dirname, dirs, files) in os.walk(root):
  for name in files:
   fullname = os.path.normpath(os.path.join(dirname, name))
   if (return_folders or os.path.isfile(fullname)):
    for pattern in pattern_list:
     if fnmatch.fnmatch(name, pattern):
      results.append(fullname)
      break
  if (not recurse):
   break
 return results

def listFiles ( root , patterns = u'*' , recurse = 1 , return_folders = 0 ) : import os . path import fnmatch pattern_list = patterns . split ( u';' ) results = [ ] for ( dirname , dirs , files ) in os . walk ( root ) : for name in files : fullname = os . path . normpath ( os . path . join ( dirname , name ) ) if ( return_folders or os . path . isfile ( fullname ) ) : for pattern in pattern_list : if fnmatch . fnmatch ( name , pattern ) : results . append ( fullname ) break if ( not recurse ) : break return results
recursively list files from parmar and martelli in the python cookbook .