delete file method of file plugin

Hi All,

I am using the delete file method of the files plugin . But it is not working . The method file.exists() is returning true . But is not able to delete the file. Please find the code below:

var file = plugins.file.convertToJSFile(absPath);
if(file.exists()){
file.deleteFile();
}

But when I am using plugins.file.convertToJSFile(‘C:\Users\ashutosl\99EC428F-8AA3-4270-A54C-62319169DE13.mov’) . It is working fine for the same file . But when I am using it in a variable . I could not able to delete the file.

Thanks in advance . Waiting for your feedback.

what do you mean with “when using it as a variable”?

Hi Johan,

Thanks for your reply . Actually I got the problem . Actually the java was not releasing the file , So we could not delete the file.

I have the same problem. When you say ‘the Java is not releasing the file’, what do you mean, and how do you get round it ?

I seem to have solved it by inserting a ```
java.lang.System.gc()

do not do that…
Especially in the webclient, never call GC() your self there, thats will kill your performance.
The problem is in the code itself not releasing (calling close()) correctly on the various file handles or in/output streams.

jcompagner:
do not do that…
Especially in the webclient, never call GC() your self there, thats will kill your performance.
The problem is in the code itself not releasing (calling close()) correctly on the various file handles or in/output streams.

What I’m doing is:

var jsfTargetTempFile = plugins.file.convertToJSFile(targetTempFile);
plugins.file.createFolder(targetDir);
plugins.file.writeFile(targetTempFile, debase64);
plugins.it2be_tools.unZip(targetTempFile, true);
java.lang.System.gc();								// -- Forces a garbage collect.
if (jsfTargetTempFile.exists())
    if (jsfTargetTempFile.canRead())
        jsfTargetTempFile.deleteFile();

Without the call to gc() there, the call to exists() comes back true, the call to canRead() comes back true, but deleteFile() fails silently and without halting the application. So to me it looks like the it2be unZip function must be what is not releasing the file handle. But I have no control over what the plugin does in that respect so it looks like I have to call gc().

Addendum: The it2be Tools plugin unZip() method has an additional parameter to specify deletion of the zip file, but that doesn’t work either.

Haha! Wouldn’t you know it - after I posted that I went and checked and the new version of the plugin does indeed seem to delete the zip file after unzipping. So problem solved!