Skip to content

Instantly share code, notes, and snippets.

@serge1
Created April 15, 2013 16:45
Show Gist options
  • Save serge1/5389465 to your computer and use it in GitHub Desktop.
Save serge1/5389465 to your computer and use it in GitHub Desktop.
Create ZIP files without specialized tools/utilities on Windows
cscript zip.vbs zip_file.zip file1.ext file2.ext file3.ext
' Syntax: cscript zip.vbs target.zip file1 file2 ... fileN
Set fso = CreateObject("Scripting.FileSystemObject")
sSourceFile = fso.GetAbsolutePathName(WScript.Arguments.Item(0))
Set objArgs = WScript.Arguments
ZipFile = fso.GetAbsolutePathName(objArgs(0))
' Create empty ZIP file and open for adding
CreateObject("Scripting.FileSystemObject").CreateTextFile(ZipFile, True).Write "PK" & Chr(5) & Chr(6) & String(18, vbNullChar)
Set zip = CreateObject("Shell.Application").NameSpace(ZipFile)
' Add all files/directories to the .zip file
For i = 1 To objArgs.count-1
zip.CopyHere(fso.GetAbsolutePathName(objArgs(i)))
'Keep script waiting until compression is done
Do Until zip.Items.Count = i
WScript.Sleep 200
Loop
Next
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment