开发者

Using VB6 + WSH with Windows Compression

Having trouble with WSH and Windows Compression.

My goal is to be able to zip up files (not folders, but individual files from var开发者_运维知识库ious locations, which I have stored in an array) using the built-in Windows Compression. I am using VB6.

Here is my routine (vb6 code):

Dim objShell
Dim objFolder
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.namespace(savePath & "\export.zip")
' --
' loop through array holding files to zip
For i = 0 To filePointer
  objFolder.CopyHere (filesToZip(i))
Next
' --
Set objShell = Nothing
Set objFolder = Nothing

It works, but issues arise when there are more than a few files. I start getting errors from Windows (presumably, its calling the compression too fast, and the zip file is locked). I cant seem to figure out how to WAIT until the COPYHERE function completes before calling the next one to avoid issues.

Does anyone have any experience with this?

Thanks -


You should be able to achieve that sort of synchronization by checking the file count in your target ZIP folder before proceeding to the next loop iteration (as suggested here and here):

For i = 0 To filePointer
  objFolder.CopyHere filesToZip(i)

  Do Until objFolder.Items.Count = i+1
    WScript.Sleep 100
  Loop
Next
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜