|
|
|
@@ -83,11 +83,12 @@ public class DVCUtils { |
|
|
|
|
|
|
|
// 检查是否目录存在 |
|
|
|
if (Files.exists(directory)) { |
|
|
|
FileUtil.deleteDir(dirPath); |
|
|
|
// FileUtil.deleteDir(dirPath); |
|
|
|
// 使用Files.walk来删除目录及其内容 |
|
|
|
// Files.walk(directory) |
|
|
|
// .sorted((path1, path2) -> path2.compareTo(path1)) // 先删除子文件夹,再删除父文件夹 |
|
|
|
// .forEach(this::deletePath); |
|
|
|
Files.walk(directory) |
|
|
|
.filter(path -> !path.equals(directory)) |
|
|
|
.sorted(Comparator.reverseOrder()) // 先删除子文件夹,再删除父文件夹 |
|
|
|
.forEach(this::deletePath); |
|
|
|
} else { |
|
|
|
Files.createDirectories(directory); |
|
|
|
} |
|
|
|
@@ -95,7 +96,7 @@ public class DVCUtils { |
|
|
|
|
|
|
|
private void deletePath(Path path) { |
|
|
|
try { |
|
|
|
Files.delete(path); |
|
|
|
Files.deleteIfExists(path); |
|
|
|
} catch (IOException e) { |
|
|
|
log.error("Unable to delete: " + path + " " + e.getMessage()); |
|
|
|
} |
|
|
|
|