def fwalk(root, predicate):
    for dirpath, dirnames, filenames in os.walk(root):
        dirnames[:] = [d for d in dirnames if predicate(r, d)]
yield dirpath, dirnames, filenames
A Python walker that can ignore directories