代码
package com.liang.fastservice.test;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IORuntimeException;
import cn.hutool.core.util.RuntimeUtil;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
/**
* @Date: 2024/10/26/15:46
* @Description:
*/
public class Test138 {
static List<String> list = new ArrayList<String>();
public static void main(String[] args) {
String path = "D:\\workspace";
File file = new File(path);
extracted(file);
}
private static void extracted(File file) {
File[] ls = FileUtil.ls(file.getAbsolutePath());
for (File l : ls) {
if (l.getName().equals("node_modules")||l.getName().equals("target")){
System.out.println("删除了"+l.getAbsolutePath());
String path = l.getAbsolutePath();
RuntimeUtil.exec("cmd /c rimraf " + path);
// list.add(l.getAbsolutePath());
}else {
if (l.isDirectory()) {
extracted(l);
}
}
}
}
}