Hi there,
does anyone know if there's a method wich allows me to delete a complete folder with files inside (obviously I also need to delete the files)?
Thanks in advance
-
delete a folder with files inside (3 messages)
- Posted by: sandro sandro
- Posted on: March 10 2005 06:11 EST
Threaded Messages (3)
- delete a folder with files inside by Rob` Clevenger on March 10 2005 16:57 EST
- delete a folder with files inside by Rob` Clevenger on March 10 2005 16:59 EST
- re: by sandro sandro on March 11 2005 06:15 EST
- delete a folder with files inside by Rob` Clevenger on March 10 2005 16:59 EST
-
delete a folder with files inside[ Go to top ]
- Posted by: Rob` Clevenger
- Posted on: March 10 2005 16:57 EST
- in response to sandro sandro
-
delete a folder with files inside[ Go to top ]
- Posted by: Rob` Clevenger
- Posted on: March 10 2005 16:59 EST
- in response to Rob` Clevenger
Here's another simplier one from: http://javaalmanac.com/egs/java.io/DeleteDir.html
// Deletes all files and subdirectories under dir.
// Returns true if all deletions were successful.
// If a deletion fails, the method stops attempting to delete and returns false.
public static boolean deleteDir(File dir) {
if (dir.isDirectory()) {
String[] children = dir.list();
for (int i=0; i<children.length; i++) {
boolean success = deleteDir(new File(dir, children[i]));
if (!success) {
return false;
}
}
}
// The directory is now empty so delete it
return dir.delete();
} -
re:[ Go to top ]
- Posted by: sandro sandro
- Posted on: March 11 2005 06:15 EST
- in response to Rob` Clevenger
first I would thank you for your help.
I apreciated your code examples.
But as I am a newbie, I wonder what would happens if I call a File object constructor with a path name that match with a file wich already existing.
Would the constructor overwrite it? Or just launch an IO ex?
Thanks again.