|
|
|
@ -7,6 +7,8 @@ import cn.hutool.core.util.ZipUtil;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.nio.charset.Charset;
|
|
|
|
|
import java.nio.file.*;
|
|
|
|
|
import java.nio.file.attribute.BasicFileAttributes;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @Author: youys
|
|
|
|
@ -27,19 +29,22 @@ public class RarUtil {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
public static void main(String[] args) throws Exception{
|
|
|
|
|
// unrar("/tmp/20230301/201905962222/20230519153409_wuiol3vn.rar", "/Users/youyongsheng/Desktop/aa");
|
|
|
|
|
// un7Z("/tmp/20230301/201905962241/20230519153506_i39sv5p2.7z", "/Users/youyongsheng/Desktop/aa");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String path = "/tmp/202505142";
|
|
|
|
|
// unzip();
|
|
|
|
|
// valid("/tmp/202405181");
|
|
|
|
|
// removeFullCode("/tmp/202405181");
|
|
|
|
|
// valid(path);
|
|
|
|
|
// removeFullCode(path);
|
|
|
|
|
removeDirectory(Paths.get(path));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void unzip(){
|
|
|
|
|
String sourceDir = "/tmp/20240518";
|
|
|
|
|
String targetDir = "/tmp/202405181";
|
|
|
|
|
String sourceDir = "/tmp/202505141";
|
|
|
|
|
String targetDir = "/tmp/202505142";
|
|
|
|
|
|
|
|
|
|
File directory = new File(sourceDir);
|
|
|
|
|
File[] studentDirs = directory.listFiles();
|
|
|
|
@ -160,4 +165,39 @@ public class RarUtil {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static void removeDirectory(Path rootPath) throws IOException {
|
|
|
|
|
Files.walkFileTree(rootPath, new SimpleFileVisitor<Path>() {
|
|
|
|
|
@Override
|
|
|
|
|
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
|
|
|
|
|
String folderName = dir.getFileName().toString();
|
|
|
|
|
if (folderName.equals("node_modules") || folderName.equals("target") || folderName.equals("dist")) {
|
|
|
|
|
System.out.println("Deleting directory: " + dir.toAbsolutePath());
|
|
|
|
|
deleteDirectoryRecursively(dir);
|
|
|
|
|
|
|
|
|
|
return FileVisitResult.SKIP_SUBTREE; // 不再进入已删除目录
|
|
|
|
|
}
|
|
|
|
|
return FileVisitResult.CONTINUE;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
// 递归删除目录
|
|
|
|
|
private static void deleteDirectoryRecursively(Path path) throws IOException {
|
|
|
|
|
Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
|
|
|
|
|
@Override
|
|
|
|
|
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
|
|
|
|
Files.deleteIfExists(file);
|
|
|
|
|
return FileVisitResult.CONTINUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
|
|
|
|
|
Files.deleteIfExists(dir);
|
|
|
|
|
return FileVisitResult.CONTINUE;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|