[英]find all paths under a directory
All I need to do is scan a directory (that could be containing sub-directories) and get a list of all the paths contained inside it. 我需要做的就是扫描目录(可能包含子目录)并获取其中包含的所有路径的列表。
EDIT: change the whole question to make it more specific! 编辑:更改整个问题,使其更具体!
My attempt would be: 我的尝试是:
try {
List<Path> pathsInDir = new ArrayList<>();
// Dir to scan
DirectoryStream<Path> newDirectoryStream = Files.newDirectoryStream(Paths.get("."));
for(Path path : newDirectoryStream) {
if(Files.isDirectory(path)) {
pathsInDir.add(path);
// recursive call to scan sub dir
} else {
// handle files.
}
}
} catch (IOException e) {
// TODO please handle the exception.
e.printStackTrace();
}
You can use the methods of java.nio.file.Path to compare the directory names. 您可以使用java.nio.file.Path的方法来比较目录名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.