Re: Exclude Directories from os.walk

2008-10-21 Thread Scott David Daniels
D wrote: Ok, my brain's apparently not working right today.. what I'd like to do is allow the user to specify a directory to exclude (ex- "C:\temp \test") - then, when os.walk gets to "C:\temp\test", it excludes that directory and all its subdirectories (so, "C:\temp\mytest\test" should still be

Re: Exclude Directories from os.walk

2008-10-21 Thread D
On Oct 21, 1:46 pm, "Orestis Markou" <[EMAIL PROTECTED]> wrote: > You then have to also check the base: > > for d in dirs[:]: >  if os.path.join(base, d) == EXCLUDED_DIR >    dirs.remove(d) > > or > > if base == EXCLUDED_DIR >   while dirs: dirs.pop() > continue > > WARNING: untest code > - Show qu

Re: Exclude Directories from os.walk

2008-10-21 Thread Orestis Markou
You then have to also check the base: for d in dirs[:]: if os.path.join(base, d) == EXCLUDED_DIR dirs.remove(d) or if base == EXCLUDED_DIR while dirs: dirs.pop() continue WARNING: untest code - Show quoted text - On Tue, Oct 21, 2008 at 6:13 PM, D <[EMAIL PROTECTED]> wrote: > Ok, my brai

Re: Exclude Directories from os.walk

2008-10-21 Thread D
Ok, my brain's apparently not working right today.. what I'd like to do is allow the user to specify a directory to exclude (ex- "C:\temp \test") - then, when os.walk gets to "C:\temp\test", it excludes that directory and all its subdirectories (so, "C:\temp\mytest\test" should still be recursed).

Re: Exclude Directories from os.walk

2008-10-21 Thread Scott David Daniels
D wrote: Hello, How can one exclude a directory (and all its subdirectories) when running os.walk()? Thanks, Doug for base, dirs, files in os.walk('wherever'): if 'RCS' in dirs: dirs.remove('RCS') As described in the os.walk docs. --Scott David Daniels [EMAIL PROTECTED] -- htt

Re: Exclude Directories from os.walk

2008-10-21 Thread Tim Golden
D wrote: Hello, How can one exclude a directory (and all its subdirectories) when running os.walk()? Just remove it from the dirnames yielded: import os for dirpath, dirnames, filenames in os.walk ("c:/temp"): print dirpath if "archive" in dirnames: dirnames.remove ("archive") TJG -

Exclude Directories from os.walk

2008-10-21 Thread D
Hello, How can one exclude a directory (and all its subdirectories) when running os.walk()? Thanks, Doug -- http://mail.python.org/mailman/listinfo/python-list