views:

536

answers:

2

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)
+1  A: 

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

Matt Dillard
+2  A: 
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.

olle
potentially could be zipping, hence not using FSO
tloach