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
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
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
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).
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
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
-
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