postprocessing in os.walk

kj at
Sun Oct 11 00:12:43 CEST 2009

Perl's directory tree traversal facility is provided by the function
find of the File::Find module.  This function accepts an optional
callback, called postprocess, that gets invoked "just before leaving
the currently processed directory."  The documentation goes on to
say "This hook is handy for summarizing a directory, such as
calculating its disk usage", which is exactly what I use it for in
a maintenance script.

This maintenance script is getting long in the tooth, and I've been
meaning to add a few enhancements to it for a while, so I thought
that in the process I'd port it to Python, using the os.walk
function, but I see that os.walk does not have anything like this
File::Find::find's postprocess hook.  Is there a good way to simulate
it (without having to roll my own File::Find::find in Python)?



More information about the Python-list mailing list