• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 241
  • Last Modified:

Deleting files in directory. Why dont this work??



File files = u.getArchive();
String[] dirListing = files.list();

  for(int i = 0;i<dirListing.length;i++)
    {
      File f = new File(dirListing[i]);
      f.delete();
    }
0
bananaDick
Asked:
bananaDick
1 Solution
 
bobbit31Commented:
here is a delete routine that i use which delete's all folders/subfolders/files in a given directory:

     public static void deleteFolder(java.io.File delFolder) throws IOException {

          if (delFolder == null || !delFolder.exists() || !delFolder.isDirectory()) {
               throw new IOException ("Specified path is not a valid folder.");
          }

          java.io.File[] files = delFolder.listFiles();

          for (int i=0;i<files.length;i++) {
               if (files[i].isDirectory()) {
                    deleteFolder(files[i]);
               }
               files[i].delete();
          }

          delFolder.delete();

     }

just call deleteFolder(u.getArchive());
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now