Skip to content

Instantly share code, notes, and snippets.

@pinei
Created October 12, 2021 04:40
Show Gist options
  • Select an option

  • Save pinei/d86d558c55471a53d66985f4b5ba5fd3 to your computer and use it in GitHub Desktop.

Select an option

Save pinei/d86d558c55471a53d66985f4b5ba5fd3 to your computer and use it in GitHub Desktop.
Zip a folder with Windows command-line or .bat
Set fso = CreateObject("Scripting.FileSystemObject")
InputFolder = fso.GetAbsolutePathName(WScript.Arguments.Item(0))
ZipFile = fso.GetAbsolutePathName(WScript.Arguments.Item(1))
' Create empty ZIP file.
CreateObject("Scripting.FileSystemObject").CreateTextFile(ZipFile, True).Write "PK" & Chr(5) & Chr(6) & String(18, vbNullChar)
Set objShell = CreateObject("Shell.Application")
Set source = objShell.NameSpace(InputFolder).Items
objShell.NameSpace(ZipFile).CopyHere(source)
' Keep script waiting until compression is done
Do Until objShell.NameSpace( ZipFile ).Items.Count = objShell.NameSpace( InputFolder ).Items.Count
WScript.Sleep 200
Loop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment