[Python-Dev] os.path.walk() lacks 'depth first' option

"Martin v. L÷wis" martin@v.loewis.de
Mon, 21 Apr 2003 21:31:18 +0200


Noah Spurrier wrote:

> I thought the names were synonymous, but a quick look on Google
> showed that post-order seems more specific to binary trees whereas
> depth first is more general, but I didn't look very hard and all my
> college text books are in storage :-) Depth first is more intuitive, but
> post order is more descriptive of what the algorithm does.
> If I were writing documentation (or reading it) I would prefer "depth 
> first".

I'm tempted to declare this off-topic: depth-first means "traverse
children before traversing siblings". Depth-first comes in three
variations: pre-order (traverse node first, then children, then 
siblings), in-order (only for binary trees: traverse left child
first, then node, then right child, then sibling), post-order (traverse
children first, then node, then siblings). There is also breadth-first:
traverse siblings first, then children.

> I write these little directory/file filters quite often. I have come across
> this problem of renaming the directories you are traversing before.

I still can't understand why you can't use os.path.walk for that.
Did you know that you can modify the list that is passed to the 
callback, and that walk will continue to visit the elements in the list?

Regards,
Martin