在调试延迟小时后的递归函数之前:是否有命令获取子目录? 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;
}关于代码的总结:
尽可能深入目录树。当目录中没有目录时,停止,将目录放到目录中,向上移动。不要在集合中检查dirs。
如果您到达开始路径,请停止并返回集。
重复步骤1和2。
PREMISE:目录结构是有限的,数据量很小。