Where is the Problem Here? Deleting Files From Dir

Hi Friends,

I has written this follwoing code to delete files of a particular folder. Here attachmentFolder is a folder. I m listing all the files of this directory, n i m deleting all the files.

Here i m getting correct count for the no of files in directory, but sometimes it deletes the file sometime not.

File attachmentFolder =new File(parentFolder);

System.out.println("Attachment Folder Name is : "+attachmentFolder.getAbsolutePath());

if(attachmentFolder.isDirectory()){

File[] files = attachmentFolder.listFiles();

System.out.println("No of Files For Attachments are: "+files.length);

for(int i=0; i<files.length; i++ ){

files[i].delete();

}

}

System.out.println("All attachments Deleted");

Can somebody tell me what could be the possible problem?

Some times it deleted some files only, also there is no error. I had written this in try-catch, it is also not giving any problem.

Thanks in advance.>

[1323 byte] By [Ashish.Mishra16a] at [2007-11-27 5:23:20]
# 1
Crosspost! http://forum.java.sun.com/thread.jspa?threadID=5176216&tstart=0
PhHeina at 2007-7-12 11:49:12 > top of Java-index,Java Essentials,New To Java...
# 2
Search this forum for "delete file" and you will have many hits, e.g. this one: http://forum.java.sun.com/thread.jspa?threadID=5172756&tstart=0It's most likely that eiher your process or an external process (virus scanner?) has an open handle to those files.
tobias.winterhaltera at 2007-7-12 11:49:12 > top of Java-index,Java Essentials,New To Java...