bananaDick
asked on
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();
}
ASKER
Sorry but I just want to delete the files in the folder, not the folder itself. + why doesn't my code work?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>>happens to return a list of files
should really say
>>happens to return a directory that's not the current directory
;-)
should really say
>>happens to return a directory that's not the current directory
;-)
bananaDick:
This old question needs to be finalized -- accept an answer, split points, or get a refund. For information on your options, please click here-> http:/help/closing.jsp#1
EXPERTS:
Post your closing recommendations! No comment means you don't care.
This old question needs to be finalized -- accept an answer, split points, or get a refund. For information on your options, please click here-> http:/help/closing.jsp#1
EXPERTS:
Post your closing recommendations! No comment means you don't care.
recommendation: points to CEHJ
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Accept CEHJ's comment as answer.
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
Thomas Boshell
EE Cleanup Volunteer
I will leave a recommendation in the Cleanup topic area that this question is:
Accept CEHJ's comment as answer.
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
Thomas Boshell
EE Cleanup Volunteer
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();
}