我想将所有子文件夹从输入文件夹复制到outputDir,但某些子文件夹除外。我用于复制的方法在这里。但我不知道如何过滤子文件夹。
public static void copyDirectory(String inputFolder, String outputDir) {
File source = new File(inputFolder);
File desc = new File(outputDir);
try {
FileUtils.copyDirectory(source, desc);
} catch (IOException e) {
e.printStackTrace();
}
}
答案 0 :(得分:0)
您可以使用以下代码:
public static void copyDirectory(String inputFolder, String outputDir) {
File source = new File(inputFolder);
File desc = new File(outputDir);
ArrayList al=new ArrayList();//contains all your directory filter names
try {
for (File file : source.listFiles()) {
if (!al.contains(file.getName())&&file.isDirectory()) {
FileUtils.copyDirectory(source, desc);
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
答案 1 :(得分:0)
试试这个。
public static void copyDirectory(String inputFolder, String outputDir) {
File source = new File(inputFolder);
File desc = new File(outputDir);
String name = source.getName();
String desti = desc.getPath() + "/" + name;
File destination = new File(desti);
destination.mkdir();
File[] subFolders = source.listFiles();
for (File subFolder : subFolders) {
if (condition satisfies){
// copy to destination folder
} else {
// Ignore
}
}
}