在调试最近一小时出界的递归函数之前:是否有获取subdirs的命令?
giveMeSubDirs(downToPath)
?
// WARNING: RECURSION out of bound or too much data
public HashSet getAllDirs(String path) {
HashSet checkedDirs = new HashSet();
HashSet allDirs = new HashSet();
String startingPath = path;
File fileThing = new File(path);
FileObject fileObject = new FileObject(fileThing);
for (FileObject dir : getDirsInDir(path)) {
// SUBDIR
while ( !checkedDirs.contains(dir)
&& !(getDirsInDir(dir.getFile().getParent()).size() == 0)) {
// DO NOT CHECK TOP DIRS if any bottom dir UNCHECKED!
while ( uncheckedDirsOnLevel(path, checkedDirs).size() > 0) {
while (getDirsInDir(path).size() == 0
|| (numberOfCheckedDirsOnLevel(path, checkedDirs)==getDirsInDir(path).size())) {
allDirs.add(new FileObject(new File(path)));
checkedDirs.add(new FileObject(new File(path)));
if(traverseDownOneLevel(path) == startingPath )
return allDirs;
//get nearer to the root
path = traverseDownOneLevel(path);
}
path = giveAnUncheckedDir(path, checkedDirs);
if ( path == "NoUnchecked.") {
checkedDirs.add(new FileObject( (new File(path)).getParentFile() ));
break;
}
}
}
}
return allDirs;
}
代码摘要:
尽可能深入到目录树。当一个dir中没有dir时,停止,将dir放在集合中,向上遍历。不要检查集合中的目录。
如果到达起始路径,请停止并返回集合。
重复步骤1和2。
前提:目录结构有限,数据量小。