| Author |
Need algorithm: treewalker without recursion.
|
Stephane Clinckart
Ranch Hand
Joined: Oct 21, 2003
Posts: 89
|
|
Hi,
I would like to make a recursion on a tree without using the recursion pattern.
Where may I find a algorithm for that?
Thanks a lot.
Stephane Clinckart
|
 |
Stephane Clinckart
Ranch Hand
Joined: Oct 21, 2003
Posts: 89
|
|
Stephane Clinckart wrote:Hi,
I would like to make a recursion on a tree without using the recursion pattern.
Where may I find a algorithm for that?
Thanks a lot.
Stephane Clinckart
I found something:
import os, os.path
startDir = "/"
directories = [startDir]
while len(directories)>0:
directory = directories.pop()
for name in os.listdir(directory):
fullpath = os.path.join(directory,name)
if os.path.isfile(fullpath):
print fullpath # That's a file. Do something with it.
elif os.path.isdir(fullpath):
directories.append(fullpath) # It's a directory, store it.
I still waiting other proposals more efficient... multithreaded by exemple.
Thanks a lot.
|
 |
 |
|
|
subject: Need algorithm: treewalker without recursion.
|
|
|