Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine when copy finishes in VBScript?

Does anyone know of a method to determine when a file copy completes in VBScript? I'm using the following to copy:

set sa = CreateObject("Shell.Application")  
set zip = sa.NameSpace(saveFile)  
set Fol = sa.NameSpace(folderToZip)  
zip.copyHere (Fol.items)
like image 531
tloach Avatar asked Mar 01 '23 07:03

tloach


2 Answers

Do Until zip.Items.Count = Fol.Items.Count
    WScript.Sleep 300
Loop

When the loop finishes your copy is finished.

But if you only want to copy and not zip, FSO or WMI is better.

If you are zipping and want them in a file you have to create the zip-file yourself, with the right header first. Else you only get compressed files/folders IIRC. Something like this:

Set FSO = CreateObject( "Scripting.FileSystemObject" )
Set File = FSO.OpenTextFile( saveFile, 2, True )
File.Write "PK" & Chr(5) & Chr(6) & String( 18, Chr(0) )
File.Close
Set File = Nothing
Set FSO = Nothing

The 2 in OpenTextFile is ForWriting.

like image 114
olle Avatar answered Mar 08 '23 06:03

olle


You may have better luck using the Copy method on a FileSystemObject. I've used it for copying, and it's a blocking call.

like image 36
Matt Dillard Avatar answered Mar 08 '23 05:03

Matt Dillard