The idiomatic way of doing the tree traversal is:
def search(a_dir):
valid_dirs = []
for dirpath, dirnames, filenames in os.walk(a_dir):
if dirtest(filenames):
valid_dirs.append(dirpath)
return valid_dirs
Also since you are given a list of filenames in the directory,
waylan wrote:
Bruce wrote:
Hi all,
I have a question about traversing file systems, and could use some
help. Because of directories with many files in them, os.walk appears
to be rather slow. I`m thinking there is a potential for speed-up since
I don`t need os.walk to report filenames
Bruce [EMAIL PROTECTED] wrote:
A little late but.. thanks for the replies, was very useful. Here`s
what I do in this case:
def search(a_dir):
valid_dirs = []
walker = os.walk(a_dir)
while 1:
try:
dirpath, dirnames, filenames = walker.next()
except StopIteration:
On 10/8/06, Tim Roberts [EMAIL PROTECTED] wrote:
Umm, may I point out that you don't NEED the os.path.exists call, because
you are already being HANDED a list of all the filenames in that directory?
You could dirtest with this much faster routinee:
def dirtest(a_dir,filenames):
for f in
Hi all,
I have a question about traversing file systems, and could use some
help. Because of directories with many files in them, os.walk appears
to be rather slow. I`m thinking there is a potential for speed-up since
I don`t need os.walk to report filenames of all the files in every
directory it
Bruce wrote:
Hi all,
I have a question about traversing file systems, and could use some
help. Because of directories with many files in them, os.walk appears
to be rather slow.
Provide more info/code. I suspect it is not os.walk itself that is slow,
but rather the code that processes its
Bruce wrote:
Hi all,
I have a question about traversing file systems, and could use some
help. Because of directories with many files in them, os.walk appears
to be rather slow. I`m thinking there is a potential for speed-up since
I don`t need os.walk to report filenames of all the files in