use of lee.study.down.model.DirInfo in project proxyee-down by monkeyWie.
the class HttpDownController method getChildDirList.
@RequestMapping("/getChildDirList")
public ResultInfo getChildDirList(@RequestBody(required = false) DirForm body) {
ResultInfo resultInfo = new ResultInfo();
List<DirInfo> data = new LinkedList<>();
resultInfo.setData(data);
File[] files;
if (body == null || StringUtils.isEmpty(body.getPath())) {
if (OsUtil.isMac()) {
files = new File("/Users").listFiles(file -> file.isDirectory() && file.getName().indexOf(".") != 0);
} else {
files = File.listRoots();
}
} else {
File file = new File(body.getPath());
if (file.exists() && file.isDirectory()) {
files = file.listFiles();
} else {
resultInfo.setStatus(ResultStatus.BAD.getCode()).setMsg("路径不存在");
return resultInfo;
}
}
if (files != null && files.length > 0) {
boolean isFileList = "file".equals(body.getModel());
for (File tempFile : files) {
if (tempFile.isFile()) {
if (isFileList) {
data.add(new DirInfo(StringUtils.isEmpty(tempFile.getName()) ? tempFile.getAbsolutePath() : tempFile.getName(), tempFile.getAbsolutePath(), true));
}
} else if (tempFile.isDirectory() && (tempFile.getParent() == null || !tempFile.isHidden()) && (OsUtil.isWindows() || tempFile.getName().indexOf(".") != 0)) {
DirInfo dirInfo = new DirInfo(StringUtils.isEmpty(tempFile.getName()) ? tempFile.getAbsolutePath() : tempFile.getName(), tempFile.getAbsolutePath(), tempFile.listFiles() == null ? true : Arrays.stream(tempFile.listFiles()).noneMatch(file -> file != null && (file.isDirectory() || isFileList) && !file.isHidden()));
data.add(dirInfo);
}
}
}
return resultInfo;
}
Aggregations