Most recursive problems can actually be solved using loops which may be easier. In the case of directory searching you would use a Stack or a Queue collection.
Stack is LastIn-FirstOut like the stack of plates in a restaurant
Queue is FirstIn-FirstOut like the queue of people getting their food in the restaurant
You put one directory into the Queue to start with then start a loop that runs While Queue Length Is Greater Than Zero,
scan the current queued directory for more directories and push them into the queu, then process the files
Obviously the loop keeps running while more directories are pushed in. To work out the directory depth in this way you'd probably have to count the number of \ in the path
If you used a stack, then the search would dig down before it went across, if you use a queue it goes across before it goes down. A simple recursive search is more like a stack, you'd have to get a bit more complicated with recursion to do a breadth-first search
-
If you can say what is confusing you about recursion I can possibly explain it
|