Where is the Problem- Not able to delete files of folder, No error also.

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. File may be of any type but not folders in attachmentFolder.

Thanks in advance.>

[1383 byte] By [Ashish.Mishra16a] at [2007-11-27 5:23:36]
# 1
According to our friend API docsfiles[i].delete();returns a boolean telling whether the deletion attempt was successful. I do not see its checking in your code.
BIJ001a at 2007-7-12 11:49:30 > top of Java-index,Java Essentials,Java Programming...