【发布时间】:2014-07-24 06:14:17
【问题描述】:
我想知道是否有使用 vbscript 压缩文件而不使用 WScript.Sleep 的方法。以下是我的脚本(实用方法被跳过);
Sub Main
Dim Path
Dim ZipFile
Dim objShell
ZipFile = WScript.Arguments(0)
Path = WScript.Arguments(1)
Dim a: a = ListDir(Path)
If UBound(a) = -1 then
WScript.Echo "No files found."
Exit Sub
End If
CreateObject("Scripting.FileSystemObject").CreateTextFile(ZipFile, True).Write "PK" & Chr(5) & Chr(6) & String(18, vbNullChar)
Set objShell = CreateObject("Shell.Application")
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
Dim FileName
For Each FileName In a
WScript.Echo FileName
objShell.NameSpace(fso.GetAbsolutePathName(ZipFile)).CopyHere(FileName)
'Required!
WScript.Sleep 4000
Next
End Sub
如果您看到代码,我正在使用 sleep 命令等待一段时间(假设文件在指定时间压缩)。但是,这会导致脚本等待相同的时间,即使对于不好的小文件也是如此。我已经在网上搜索过是否有同步压缩文件,但无法得到答案。
【问题讨论】: