os.walk() maxdepth

G

GMTaglia

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
 
T

Tim Peters

]GMTaglia said:
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).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,666
Latest member
selsetu

Latest Threads

Top