使用 VB6 +带 Windows 压缩的 WSH

发布于 2024-08-27 13:37:03 字数 672 浏览 7 评论 0原文

WSH 和 Windows 压缩遇到问题。

我的目标是能够使用内置的 Windows 压缩功能压缩文件(不是文件夹,而是来自不同位置的单个文件,我将其存储在数组中)。我用的是VB6。

这是我的例程(vb6 代码):

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

它可以工作,但是当文件数量较多时就会出现问题。 我开始从 Windows 中收到错误(大概是它调用压缩速度太快,并且 zip 文件被锁定)。我似乎无法弄清楚如何等待 COPYHERE 函数完成,然后再调用下一个函数以避免出现问题。

有人有这方面的经验吗?

谢谢 -

Having trouble with WSH and Windows Compression.

My goal is to be able to zip up files (not folders, but individual files from various 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 -

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

入画浅相思 2024-09-03 13:37:03

在继续下一个循环迭代之前,您应该能够通过检查目标 ZIP 文件夹中的文件计数来实现这种同步(如建议的 此处此处 >):

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

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文