Pausing Code to wait for file copy

Questions, tips and tricks and techniques for scripting in Servoy

Pausing Code to wait for file copy

Postby kschuster » Sat Feb 04, 2012 12:23 am

I'm playing around with copying file and zipping them. Its all pretty sequential i.e. copy file now zip it. I just tried to copy a 2 gig file and zip it - it failed and I suspect the reason is the copy process didn't complete before the code executed to zip the file.

Is there a more graceful way to do this..? I'm think some kind of a "pause" to allow time for the copy to complete. Better yet would be if the zip function zipped TO a folder. (I'm working with IT2Be tools to perform the zip)

any thoughts?

Code: Select all
function getFile(event) {

   var f = plugins.file.showFileOpenDialog(1,null,false,new Array("TXT and CSV","txt","csv"));
   f = plugins.file.convertToJSFile(f)
   gfileFull = f
   gfileName = f.getName();
      
      var fcopy = plugins.file.createFile("c:/temp/" + gfileName);
      application.output('ffcopy:' + fcopy);
      if(!plugins.file.copyFile(f, fcopy)){
         
         application.output("failed");

      }else{
         application.output(plugins.it2be_tools.zip(f.getAbsolutePath(),true));
         application.output("success");

      }
}

kschuster
 
Posts: 53
Joined: Fri Mar 28, 2008 4:42 am
Location: Houston, TX

Re: Pausing Code to wait for file copy

Postby mboegem » Sat Feb 04, 2012 12:37 am

Take a look at the functions streamFilesFromServer or streamFilesToServer (depending on which way you want to go)
These functions allow you to specify a callback method, which will run once the task is completed.
It gets even better: streaming will happen in the background, so your users can continue to do their work in the meantime... :-)

Hope this helps!
_____________________
Marc Boegem
Solutiative / JBS Group, Partner
• Servoy Certified Developer
• Servoy Valued Professional
• Freelance SAN Developer

Image
User avatar
mboegem
 
Posts: 1531
Joined: Sun Oct 14, 2007 1:34 pm
Location: Amsterdam

Re: Pausing Code to wait for file copy

Postby kschuster » Sat Feb 04, 2012 12:49 am

I'll look at that - thanks
kschuster
 
Posts: 53
Joined: Fri Mar 28, 2008 4:42 am
Location: Houston, TX


Return to Methods

Who is online

Users browsing this forum: No registered users and 1 guest