0

我想将所有子文件夹从输入文件夹复制到 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();
            }
        }
4

2 回答 2

1

您好使用以下代码:

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();
    }
}
于 2013-03-14T12:33:04.807 回答
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
             }

        }

    }
于 2013-03-14T12:34:08.773 回答