Delete directory on windows

I need help...

I'm writing a project to make a directory synchronizer, with many policy.

I have to write a method to delete all the input directory, and i write this:

publicboolean 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)returnfalse;

}

}

// The directory is now empty so delete it

System.gc();

return dir.delete();

}

So i test it and the result is:

on Linux Debian it will delete all the directory

on Windows Xp no.

I tried to change dir.delete() in to dir.deleteOnExit() but it's the same, it doesn't work on win!!!!

I have no ideas, please help me.>

[1383 byte] By [murdok83@gmail.coma] at [2007-11-26 17:41:09]
# 1
My idea would be to look at what happens instead of the directory being deleted.
DrClapa at 2007-7-9 0:09:20 > top of Java-index,Java Essentials,Java Programming...
# 2
Read here: http://forum.java.sun.com/thread.jspa?threadID=166271&tstart=45
kevjavaa at 2007-7-9 0:09:20 > top of Java-index,Java Essentials,Java Programming...
# 3

You may still have some resource locking one of the files you are trying to delete. This is a cleaned up version of your code, if you are using 1.5.

public static boolean deleteDir(File dir) {

if (dir.isDirectory()) {

File [] children = dir.listFiles();

for (File child : children) {

System.out.println("Deleting " + child.getPath());

return deleteDir(child);

}

}

// The directory is now empty so delete it

return dir.delete();

}

No need to do dir.list then create a new file object from that string when you can just do a dir.listFiles().

~Tim

SomeoneElsea at 2007-7-9 0:09:20 > top of Java-index,Java Essentials,Java Programming...