2013-03-14 4 views
0

일부 하위 폴더를 제외하고 입력 폴더의 모든 하위 폴더를 outputDir에 복사하려고합니다. 복사에 사용하는 방법은 여기에 있습니다. 하지만 하위 폴더를 필터링하는 방법을 모르겠습니다.java의 일부 하위 폴더를 제외하고 모든 하위 폴더를 하나에서 다른 폴더로 복사 하시겠습니까?

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(); 
    } 
} 
+0

가능한 DUP http://stackoverflow.com/questions/7191635/java-copy-a-folder-excluding-some-internal-file –

+0

이를 참조하십시오 http://stackoverflow.com/questions/7191635/java-copy-a-folder-exclu-some-internal-file –

답변

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 
      } 

     } 

    } 
+0

코드를 사용해 보았지만 FileUtils.copyDirectory (source, desc)를 사용하고 있기 때문에 작동하지 않습니다. 그리고 이것은 원본 dir에서 desc dir로 모든 데이터를 복사합니다. –

0

이 시도 :

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(); 
      } 
     } 
관련 문제