Can't delete a remote file

Hi

Am building a document management system and using the new streamto/streamfrom server functions.

Am at the stage now where if the user wants to delete a version of a file from the solution I also want to delete the remote file. Using the following code:

var remote_name = "/" + document_master_to_document_versions.remote_file_name;
var f = plugins.file.convertToRemoteJSFile(remote_name);
if (f && f.canRead())
{
  application.output('File can be read.');
}
if (plugins.file.deleteFile(f));
{
  application.output('File deleted.');
}

this code produces the correct console outputs and shows no errors but the file remains in the remote file directory on the server.

Any help would be appreciated.

Don’t use plugins.file.deleteFile on a JSFile that you have created from convertToRemoteJSFile… This method is used for local files only.

What you can do though (and it will work for local files as well) is call delete() directly on the JSFile:

var remote_name = "/" + document_master_to_document_versions.remote_file_name;
var f = plugins.file.convertToRemoteJSFile(remote_name);
if (f && f.canRead())
{
  application.output('File can be read.');
}
if (f.delete());
{
  application.output('File deleted.');
}

Hi Patrick

I think you mean this

var remote_name = "/" + document_master_to_document_versions.remote_file_name;
var f = plugins.file.convertToRemoteJSFile(remote_name);
if (f && f.canRead())
{
  application.output('File can be read.');
}
if (f.deleteFile());
{
  application.output('File deleted.');
}

Works perfectly, have found it pretty amazing what you can do with the new file plugin features. Have built a reasonable doc management system with full versioning and ‘read-requests’ in a matter of days :D

Thanks so much for your help, owe you a beer or 3 at Servoyworld!

Yes, deleteFile indeed! I was looking at the source of the plugin where you have both, but delete seems to be a reserved word.

And for the beer, thanks, I have a bad feeling I’m going to get drunk at ServoyWorld ;)

var selectedFile = "C:/temp/abc.zip";
var tempSelectedFile = selectedFile.substring(0,selectedFile.indexOf(".zip"))+"_temp.zip";
var bCopyFile = plugins.file.copyFile(selectedFile,tempSelectedFile);	
var unZipFile = plugins.it2be_tools.unZip(tempSelectedFile, false);
var jsFileTempSelectedFile = plugins.file.convertToJSFile(tempSelectedFile);
application.output("Delete temp File=" +plugins.file.deleteFile(tempSelectedFile));
application.output("jsFileTempSelectedFile.deleteFile()=" +jsFileTempSelectedFile.deleteFile());

both deleteFile returned false. How would I know the reason?
i am doing my test in client/server setup.

Most probably the files are still locked by the copy/unzip process.

How can I be sure the file is free to delete?

Dunno. Maybe there’s a release method in the tools plugin?