problem with os.path.walk

Martin von Loewis loewis at informatik.hu-berlin.de
Sat Aug 11 05:28:39 EDT 2001


Jiba <a11w at SoftHome.net> writes:

> what about walking in the subdirectories BEFORE walking in the top
> directory :

Good point. Of course, changing it may break backwards-compatibility
with code that expects to do the directory first, then subdirectories.

Please note that you can easily work around this problem: Inside the
callback function, you can remove the file names from the list if you
remove the files from the disk. Actually, some people may do that
already, which would cause an even bigger compatibility problem
(you'll note that you could also add directories to the list, which it
would then traverse into).

Please have a look at the walk documentation, at

http://www.python.org/doc/current/lib/module-os.path.html

it explicitly mentions the option of modifying the names list.

Regards,
Martin



More information about the Python-list mailing list