我发现(显然为所有人工作)只需要修改的脚本(路径):
Sub NewZip(pathToZipFile)
'WScript.Echo "Newing up a zip file (" & pathToZipFile & ") "
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
Dim file
Set file = fso.CreateTextFile(pathToZipFile)
file.Write Chr(80) & Chr(75) & Chr(5) & Chr(6) & String(18, 0)
file.Close
Set fso = Nothing
Set file = Nothing
WScript.Sleep 500
End Sub
Sub CreateZip(pathToZipFile, dirToZip)
'WScript.Echo "Creating zip (" & pathToZipFile & ") from (" & dirToZip & ")"
Dim fso
Set fso= Wscript.CreateObject("Scripting.FileSystemObject")
pathToZipFile = fso.GetAbsolutePathName(pathToZipFile)
dirToZip = fso.GetAbsolutePathName(dirToZip)
If fso.FileExists(pathToZipFile) Then
'WScript.Echo "That zip file already exists - deleting it."
fso.DeleteFile pathToZipFile
End If
If Not fso.FolderExists(dirToZip) Then
'WScript.Echo "The directory to zip does not exist."
Exit Sub
End If
NewZip pathToZipFile
dim sa
set sa = CreateObject("Shell.Application")
Dim zip
Set zip = sa.NameSpace(pathToZipFile)
'WScript.Echo "opening dir (" & dirToZip & ")"
Dim d
Set d = sa.NameSpace(dirToZip)
' Look at http://msdn.microsoft.com/en-us/library/bb787866(VS.85).aspx
' for more information about the CopyHere function.
zip.CopyHere d.items, 4
Do Until d.Items.Count <= zip.Items.Count
Wscript.Sleep(200)
Loop
End Sub
有人能举例说明这个脚本应该是什么样子的吗真正的路径?我正在尝试,但对我不起作用。
此脚本仅由两个子例程组成,因此永远不会执行任何内容。
在文件底部添加以下行,它应该可以工作(假设subs中的代码是健全的,我还没有测试):
CreateZip "c:outputtest.zip" "c:input"
这将按顺序执行以下操作:
- 检查输出文件是否存在。如果是,它将删除它
- 检查输入文件夹是否存在,如果不存在,脚本将退出
- 调用
NewZip
sub,它只创建一个"空".zip文件 - 将文件复制到zip文件中
- 暂停一段时间,可能是为了确保在ZIP完成复制之前不会尝试访问它
input
文件夹的内容现在将位于output
文件夹的zip文件中。