Created
April 15, 2013 16:45
-
-
Save serge1/5389465 to your computer and use it in GitHub Desktop.
Create ZIP files without specialized tools/utilities on Windows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cscript zip.vbs zip_file.zip file1.ext file2.ext file3.ext |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' 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