469,903 Members | 1,698 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,903 developers. It's quick & easy.

os.walk() maxdepth

I've googled a lot but I couldn't figure out how to implement a maxdepth in
os.walk(), does anybody had the necessity to do something like that?

thanks in advance and....
....as usual forgive my english

--
Liquid
http://softwarelibero.kuht.it <-> www.kuht.it
Jul 18 '05 #1
1 11809
]GMTaglia <li****@nospamkuht.it>]
I've googled a lot but I couldn't figure out how to implement a maxdepth in
os.walk(), does anybody had the necessity to do something like that?


No, but

for root, dirs, files in os.walk(whatever):
....
if root.count(os.sep) >= CUTOFF_DEPTH:
del dirs[:]

will prune the search based on the number of separator characters in
the directory currently being visited. Mutating dirs in-place
controls which directories the os.walk generator looks at when it's
resumed. This is only effective in a top-down walk (which is the
default).
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Marcello Pietrobon | last post: by
6 posts views Thread by rbt | last post: by
7 posts views Thread by KraftDiner | last post: by
6 posts views Thread by Bruce | last post: by
9 posts views Thread by silverburgh.meryl | last post: by
2 posts views Thread by gregpinero | last post: by
2 posts views Thread by Martin Marcher | last post: by
reply views Thread by Jeff McNeil | last post: by
4 posts views Thread by Jeff Nyman | last post: by
1 post views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.