title: How to save only zip files and remove other folders using java?
body: <p>Here i have Folder(Books)in that i have 3 sub folders named:<strong>sub1, sub2, sub3</strong> and <strong>sub1 have 2 files</strong>, <strong>sub2 have 3 files</strong>, <strong>sub3 have 4 files</strong>. And <strong>sub1.zip</strong>,<strong>sub2.zip</strong> and <strong>sub3.zip</strong>. I want to <strong>keep only zip files</strong> and <strong>delete sub1, sub2, sub3 folders</strong> of Books. With my code I'm able to delete all inside files of sub1 folder, sub2, sub3 finally all folders becoming empty, then <strong>how can I delete sub1,sub2 and sub3 folders</strong>.</p>
  
  <pre><code>public void SaveZipFiles(File destwithouAudio) throws IOException {
      File[] listOfFiles = destwithouAudio.listFiles();
      for (File listOfFile : listOfFiles) {
          if (listOfFile.getName().endsWith(".zip")) {
          } else {
              File FolderInside = new File(listOfFile.getAbsolutePath());
              File[] listOfFilesInside = FolderInside.listFiles();
              for (File listOfFilesInside1 : listOfFilesInside) {
                  File deleteFolder = new File(listOfFilesInside1.getAbsolutePath());
                  //System.out.println(""+listOfFilesInside[j]);
                  RecursiveDelete(deleteFolder);
              }
          }
      }
  }
  </code></pre>
  
  <p>RecursiveDelete method code is:</p>
  
  <pre><code>public static void RecursiveDelete(File file) throws IOException {
      if (file.isDirectory()) {
          if (file.list().length == 0) {
              file.delete();
              System.out.println("Directory is deleted : " + file.getAbsolutePath());
          } else {
              String files[] = file.list();
              for (String temp : files) {
                  File fileDelete = new File(file, temp);
                  RecursiveDelete(fileDelete);
              }
              if (file.list().length == 0) {
                  file.delete();
                  System.out.println("Directory is deleted : " + file.getAbsolutePath());
              }
          }
      } else {
          file.delete();
          System.out.println("File is deleted : " + file.getAbsolutePath());
      }
  }
  </code></pre>
  
  <p>After deleting all files from <strong>sub1,sub2,sub3</strong> foldersIi need to delete all <strong>sub1,sub2,sub3</strong> folders.</p>
  
  <p>Where to change the code?</p>