본문 바로가기
JAVA

자바 폴더 삭제

by 정윤재 2009. 2. 11.

자바 폴더 삭제 로직이다.(디렉토리까지 다 알아서 지워진다.)

public boolean deleteFolder(File targetFolder){
 
      File[] childFile = targetFolder.listFiles();
      boolean confirm = false;
      int size = childFile.length;
 
      if (size > 0) {
 
          for (int i = 0; i < size; i++) {
 
              if (childFile[i].isFile()) {
 
                  confirm = childFile[i].delete();
 
                  System.out.println(childFile[i]+":"+confirm + " 삭제");
                 
              } else {
 
                  deleteFolder(childFile[i]);
 
              }
 
          }
 
      }
 
  
 
      targetFolder.delete();
 
      System.out.println(targetFolder + " 폴더삭제됨삭제");
      System.out.println(targetFolder+":"+confirm + " 삭제");
     
      return (!targetFolder.exists());
 
   
 }//deleteFolder


댓글