Re: newbie : prune os.walk

2005-03-11 Thread Tim Roberts
Rory Campbell-Lange <[EMAIL PROTECTED]> wrote: > >Hi. How can I list root and only one level down? I've tried setting dirs >= [] if root != start root, but it doesn't work. I clearly don't >understand how the function works. I'd be grateful for some pointers. The statement dir = [] does not ac

Re: newbie : prune os.walk

2005-03-10 Thread Scott David Daniels
Rory Campbell-Lange wrote: Hi. How can I list root and only one level down? I've tried setting dirs = [] if root != start root, but it doesn't work. I clearly don't understand how the function works. I'd be grateful for some pointers. base = '/tmp/test' for root, dirs, files in os.walk(base

Re: newbie : prune os.walk

2005-03-10 Thread Peter Hansen
Rory Campbell-Lange wrote: Hi. How can I list root and only one level down? I've tried setting dirs = [] if root != start root, but it doesn't work. It sounds like you are trying to take advantage of the feature described in the docs where "the caller can modify the dirnames list in-place (perhaps

Re: newbie : prune os.walk

2005-03-10 Thread Diez B. Roggisch
Untestet: def foo(base, depth=2): for root, dirs, files in os.walk(base, True): if len(root.split(os.sep)) < depth: yield root, dirs, files for root, dirs, files in foo("/tmp"): print root, dirs, files -- Regards, Diez B. Roggisch -- http://mail.python.org/ma