Skip to content

Instantly share code, notes, and snippets.

@realdomdom
Last active March 12, 2022 21:08
Show Gist options
  • Save realdomdom/66283f8b7cf90f45726dfa4e32862e2c to your computer and use it in GitHub Desktop.
Save realdomdom/66283f8b7cf90f45726dfa4e32862e2c to your computer and use it in GitHub Desktop.
unzip c:\path\to\file.zip [directory]
<!-- :
@echo off
if [%1] equ [] (echo Missing file parameter. && echo unzip c:\path\to\file.zip [directory] && exit /b 1)
if %1 not exist (echo File not found. && echo unzip c:\path\to\file.zip [directory] && exit /b 2)
if [%2] not equ [] (if %2 not exist (mkdir %2 && if %errorlevel% not 0 (echo Invalid parameter. && echo unzip c:\path\to\file.zip [directory] && exit /b 3)))
if [%2] equ [] (cscript //nologo "%~f0?.wsf" /ZipFile:%1 /ExtractTo:%~dp0 //job:unzip && exit /b)
cscript //nologo "%~f0?.wsf" /ZipFile:%1 /ExtractTo:%2 //job:unzip
exit /b
--->
<package>
<job id="unzip">
<script language="VBScript">
Set Args = WScript.Arguments.Named
ZipFile = Args.Item("ZipFile")
ExtractTo = Args.Item("ExtractTo")
Set fso = CreateObject("Scripting.FileSystemObject")
If NOT fso.FolderExists(ExtractTo) Then
fso.CreateFolder(ExtractTo)
End If
set objShell = CreateObject("Shell.Application")
set FilesInZip=objShell.NameSpace(ZipFile).items
objShell.NameSpace(ExtractTo).CopyHere(FilesInZip)
Set fso = Nothing
Set objShell = Nothing
</script>
</job>
</package>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment