os.walk() maxdepth

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • GMTaglia

    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
  • Tim Peters

    #2
    Re: os.walk() maxdepth

    ]GMTaglia <liquid@nospamk uht.it>][color=blue]
    > 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?[/color]

    No, but

    for root, dirs, files in os.walk(whateve r):
    ....
    if root.count(os.s ep) >= 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).

    Comment

    Working...