[英]VBS zipping script
I found (apparently working for everybody) script which only needs to be modified (paths): 我发现(显然为每个人工作)脚本,只需要修改(路径):
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
Can anybody give example how this script should look like with real paths? 谁能举例说明该脚本在真实路径下的外观吗? I'm trying but it's not working for me.
我正在尝试,但对我不起作用。
This script consists solely of two subroutines and thus will never execute anything. 该脚本仅包含两个子例程,因此将永远不会执行任何操作。
Add the following line to the bottom of the file and it should work (given that the code in the subs is sound, I have not tested): 将以下行添加到该文件的底部,它应该可以工作(假设subs中的代码是正确的,我尚未测试):
CreateZip "c:\output\test.zip" "c:\input\"
This will do the following, in order: 这将按顺序执行以下操作:
NewZip
sub which just creates an "empty" .zip file. NewZip
子项,该子项仅创建一个“空” .zip文件。 The contents of the input
folder will now be in the zip file in the output
folder. 现在,
input
文件夹的内容将位于output
文件夹的zip文件中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.