Limitation of os.walk

kj no.email at please.post
Tue May 11 15:49:53 EDT 2010




I want implement a function that walks through a directory tree
and performs an analsysis of all the subdirectories found.  The
task has two essential requirements that, AFAICT, make it impossible
to use os.walk for this:

1. I need to be able to prune certain directories from being visited.

2. The analysis on each directory can be performed only after it
   has been performed on all its subdirectories.

Unless I'm missing something, to do (1), os.walk must be run with
topdown=True, whereas to do (2) it must be run with topdown=False.

Is there a work around that I'm missing?

TIA!

~K

PS: I never understood why os.walk does not support hooks for key
events during such a tree traversal.



More information about the Python-list mailing list