Page 1 of 1

Can't delete a remote file

PostPosted: Tue Jan 11, 2011 2:47 am
by rodneysieb
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:

Code: Select all
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.

Re: Can't delete a remote file

PostPosted: Tue Jan 11, 2011 8:22 am
by ptalbot
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:
Code: Select all
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.');
}

Re: Can't delete a remote file

PostPosted: Tue Jan 11, 2011 10:22 am
by rodneysieb
Hi Patrick

I think you mean this
Code: Select all
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!

Re: Can't delete a remote file

PostPosted: Tue Jan 11, 2011 3:26 pm
by ptalbot
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 ;)

Re: Can't delete a remote file

PostPosted: Wed Feb 08, 2012 7:48 am
by pogie.nocedo
Code: Select all
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.

Re: Can't delete a remote file

PostPosted: Wed Feb 08, 2012 8:57 am
by ptalbot
Most probably the files are still locked by the copy/unzip process.

Re: Can't delete a remote file

PostPosted: Wed Feb 08, 2012 10:29 am
by pogie.nocedo
How can I be sure the file is free to delete?

Re: Can't delete a remote file

PostPosted: Wed Feb 08, 2012 6:08 pm
by ptalbot
Dunno. Maybe there's a release method in the tools plugin?