Storing the visited nodes (directories) somewhere and then testing to see if they are visited or not everytime you try to do something is the easiest way. If you could flag them as visited by changing their names in a temporary tree, that could be other way.. but what you are doing sounds just about right. Or you could try something like this:
Code:
class Node {
String name; // name of the directory
int node; // 0 for not visited and 1 for visited
}
Change the values as you visit the nodes.. many different ways of doing it.. Choose one implementation and stick with it.