Can't delete a remote file

Questions, tips and tricks and techniques for scripting in Servoy

Can't delete a remote file

Postby rodneysieb » Tue Jan 11, 2011 2:47 am

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.
Regards,
Rodney Siebenhausen

logic@work
Brisbane, Australia
rodneysieb
 
Posts: 260
Joined: Tue Feb 14, 2006 9:11 am
Location: Brisbane, Australia

Re: Can't delete a remote file

Postby ptalbot » Tue Jan 11, 2011 8:22 am

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.');
}
Patrick Talbot
Freelance - Open Source - Servoy Valued Professional
http://www.servoy-stuff.net
https://www.servoyforge.net
--------------------------------------------
Servoy 5.2.16 / 6.0.9 / 6.1.6 / 7.3.1
All OSes / Java 5 & 6 & 7
User avatar
ptalbot
 
Posts: 1616
Joined: Wed Mar 11, 2009 5:13 am
Location: Montreal, QC

Re: Can't delete a remote file

Postby rodneysieb » Tue Jan 11, 2011 10:22 am

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!
Regards,
Rodney Siebenhausen

logic@work
Brisbane, Australia
rodneysieb
 
Posts: 260
Joined: Tue Feb 14, 2006 9:11 am
Location: Brisbane, Australia

Re: Can't delete a remote file

Postby ptalbot » Tue Jan 11, 2011 3:26 pm

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 ;)
Patrick Talbot
Freelance - Open Source - Servoy Valued Professional
http://www.servoy-stuff.net
https://www.servoyforge.net
--------------------------------------------
Servoy 5.2.16 / 6.0.9 / 6.1.6 / 7.3.1
All OSes / Java 5 & 6 & 7
User avatar
ptalbot
 
Posts: 1616
Joined: Wed Mar 11, 2009 5:13 am
Location: Montreal, QC

Re: Can't delete a remote file

Postby pogie.nocedo » Wed Feb 08, 2012 7:48 am

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.
pogie.nocedo
 
Posts: 41
Joined: Tue Feb 07, 2012 1:55 am

Re: Can't delete a remote file

Postby ptalbot » Wed Feb 08, 2012 8:57 am

Most probably the files are still locked by the copy/unzip process.
Patrick Talbot
Freelance - Open Source - Servoy Valued Professional
http://www.servoy-stuff.net
https://www.servoyforge.net
--------------------------------------------
Servoy 5.2.16 / 6.0.9 / 6.1.6 / 7.3.1
All OSes / Java 5 & 6 & 7
User avatar
ptalbot
 
Posts: 1616
Joined: Wed Mar 11, 2009 5:13 am
Location: Montreal, QC

Re: Can't delete a remote file

Postby pogie.nocedo » Wed Feb 08, 2012 10:29 am

How can I be sure the file is free to delete?
pogie.nocedo
 
Posts: 41
Joined: Tue Feb 07, 2012 1:55 am

Re: Can't delete a remote file

Postby ptalbot » Wed Feb 08, 2012 6:08 pm

Dunno. Maybe there's a release method in the tools plugin?
Patrick Talbot
Freelance - Open Source - Servoy Valued Professional
http://www.servoy-stuff.net
https://www.servoyforge.net
--------------------------------------------
Servoy 5.2.16 / 6.0.9 / 6.1.6 / 7.3.1
All OSes / Java 5 & 6 & 7
User avatar
ptalbot
 
Posts: 1616
Joined: Wed Mar 11, 2009 5:13 am
Location: Montreal, QC


Return to Methods

Who is online

Users browsing this forum: No registered users and 1 guest