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\te st", it excludes that
directory and all its subdirectories (so, "C:\temp\mytest \test" should
still be recursed). Isn't what's posted above keying just upon the
final subdirectory (i.e. "test") instead of the full path as a whole?
for d in dirs[:]:
if os.path.join(ba se, 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 <dmcclouds@gmai l.comwrote:
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\te st", it excludes that
directory and all its subdirectories (so, "C:\temp\mytest \test" should
still be recursed). Isn't what's posted above keying just upon the
final subdirectory (i.e. "test") instead of the full path as a whole?
>
--
On Oct 21, 1:46 pm, "Orestis Markou" <ores...@oresti s.grwrote:
You then have to also check the base:
>
for d in dirs[:]:
if os.path.join(ba se, 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 <dmcclo...@gmai l.comwrote:
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\te st", it excludes that
directory and all its subdirectories (so, "C:\temp\mytest \test" should
still be recursed). Isn't what's posted above keying just upon the
final subdirectory (i.e. "test") instead of the full path as a whole?
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\te st", it excludes that
directory and all its subdirectories (so, "C:\temp\mytest \test" should
still be recursed). Isn't what's posted above keying just upon the
final subdirectory (i.e. "test") instead of the full path as a whole?
>
forbidden = 'a/b/c'
home, final = os.path.split(c anonical(forbid den))
for base, dirs, files in os.walk('wherev er'):
if final in dirs and home == canonical(base) :
dirs.remove(fin al)
Comment