From a /msg request for dragonchild, here's pseudocode to do a directory traversal without recursion.
# Traverse the filesystem
push to stack /
while currentdirectory = pop stack
open the currentdirectory
foreach pathname in this directory
if it's also a directory, push it (full path)
on the stack
close the current directory
As opposed to a recursive solution:
call traverse(/)
function traverse (currentdirectory)
open currentdirectory
foreach pathname in this directory
if it's also a directory, traverse(pathname)
close currentdirectory