visit() is yielding two different things, which is messing you up. First, it yields a directory object, then it yields a generator. You should change it so it always returns one type of thing, and it needs a base case so that it terminates.
That'll do a DFS on your file structure, which might not be what you want.
edit: err, yeah, his thing is the same, but uses your directory class (FYI: classes are usually capitalized). Brain's not firing on all cylinders.
Code:
def visit(dir1):
if os.isdir(dir1):
for j in os.listdir(dir1):
for k in visit(os.path.join(dir1, j)):
yield k
else:
yield dir1
That'll do a DFS on your file structure, which might not be what you want.
edit: err, yeah, his thing is the same, but uses your directory class (FYI: classes are usually capitalized). Brain's not firing on all cylinders.