Hi
I'm new to the list. i found a bad behaviour of os.walk that i can reproduce 100% but didn't find an answer to why it does that
I have the folowing tree:
t:\dir1
t:\dir1\2000
t:\dir1\2001
t:\dir1\content
t:\dir2
t:\dir2\2000
t:\dir2\2001
t:\dir2\2002
t:\dir2\2003
t:\dir2\2004
t:\dir2\content
t:\dir2\templates
what i wanted was to loop in each dir and skip the years (i don't want to touch archive). So i wrote:
for root, dirs, files in os.walk('t:\'):
# -- do stuff
print "working on", root
# -- stuff done
print 'DEBUG: dirs =', dirs
for d in dirs:
# -- remove archive
if d[:2] == '20':
print "--- removing:", d
dirs.remove(d)
And when i run it i got the following output
working on t:\
working on t:\dir1
DEBUG: dirs = ['2000', '2001', 'content']
--- removing 2000
--- removing 2001
working on t:\dir1\content
working on t:\dir2
DEBUG: dirs = ['2000', '2001', '2003', '2002', '2004', 'content'] <- why is this in this sequence?
--- removing 2000
--- removing 2003
--- removing 2004
working on t:\dir2\2001
.
.
.
I am nuts?
running as os.walk('t:\dir2') make it ignore the same dirs.
i'm using python 2.3 on windows 2000.
The t: drive is a webdav mount.
Thanks,
Gabriel
-- http://mail.python.org/mailman/listinfo/python-list