from __future__ import generators import os def dirwalk(dir): "walk a directory tree, using a generator" for f in os.listdir(dir): fullpath = os.path.join(dir,f) if os.path.isdir(fullpath) and not os.path.islink(fullpath): for x in dirwalk(fullpath): # recurse into subdir yield x else: yield fullpath