//删除文件或文件夹
public static void scanAllFile(File root, String... suffix) {
for (File file : root.listFiles()) {
if (isMatch(file.getName(), suffix)) {
delAllFiles(file);
} else if (file.isDirectory()) {
scanAllFile(file, suffix);
}
}
}
// 匹配类型
public static boolean isMatch(String name, String... suffix) {
for (String s : suffix) {
if (name.endsWith(s)) {
return true;
}
}
return false;
}
// 清空指定路径下所有的文件或文件夹
public static void delAllFiles(File file) {
if (file.isDirectory()) {
File[] files = file.listFiles();
for (File f : files) {
if (f.isDirectory()) {
delAllFiles(f);
} else {
f.delete();
}
}
}
file.delete();
}
// 找到指定目录的所有文件
public static String findAllFiles(String path) {
String fileName = path;
File file = new File(path);
File[] files = file.listFiles();
if (files.length > 0) {
fileName += "\\" + files[0].getName();
System.out.println(fileName);
}
return fileName;
}
public static void main(String[] args) {
scanAllFile(new File("F:\\est\\xml"), ".svn");
}