> >>> allowed = ['.txt', '.sql'] > >>> for path, dirs, files in os.walk("."): > ... for f in files: > ... if splitext(f)[1].lower() not in allowed: continue
Additionally, if you really do want to specify wildcards: >>> allowed = ['*.txt', 'README*', '*.xml', '*.htm*'] >>> from glob import fnmatch >>> import os >>> for path, dirs, files in os.walk("."): ... good_files = [] ... for pat in allowed: ... good_files.extend(fnmatch.filter(files, pat)) ... if good_files: break ... for f in good_files: ... print "doing something with %s" % os.path.join(path, f) -tkc -- http://mail.python.org/mailman/listinfo/python-list