aspose file tools*
The moose likes Performance and the fly likes Need algorithm: treewalker without recursion. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Performance
Bookmark "Need algorithm: treewalker without recursion." Watch "Need algorithm: treewalker without recursion." New topic
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need algorithm: treewalker without recursion.