?
Solved

Deleting files in directory. Why dont this work??

Posted on 2003-02-21
2
Medium Priority
?
237 Views
Last Modified: 2010-03-31


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
Comment
Question by:bananaDick
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 7994572
0
 
LVL 18

Accepted Solution

by:
bobbit31 earned 180 total points
ID: 7994582
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 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn different types of Android Layout and some basics of an Android App.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month11 days, 2 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question