I want to make a BAT file that will ZIP or UNZIP a file. For zipping a file, I have found this question: Can you zip a file from the command prompt using ONLY Windows' built-in capability to zip files?

The answers given there are great and working for me, but I couldn't find any information about how to unzip the files. Like in the link, I can't assume any third-party tools (except winRAR).

Thanks ahead and sorry for English mistakes

up vote 2 down vote accepted

This batch file code will help you to unzip a file.

@echo off
setlocal
cd /d %~dp0
Call :UnZipFile "C:\Temp\" "c:\FolderName\batch.zip"
exit /b

:UnZipFile <ExtractTo> <newzipfile>
set vbs="%temp%\_.vbs"
if exist %vbs% del /f /q %vbs%
>%vbs%  echo Set fso = CreateObject("Scripting.FileSystemObject")
>>%vbs% echo If NOT fso.FolderExists(%1) Then
>>%vbs% echo fso.CreateFolder(%1)
>>%vbs% echo End If
>>%vbs% echo set objShell = CreateObject("Shell.Application")
>>%vbs% echo set FilesInZip=objShell.NameSpace(%2).items
>>%vbs% echo objShell.NameSpace(%1).CopyHere(FilesInZip)
>>%vbs% echo Set fso = Nothing
>>%vbs% echo Set objShell = Nothing
cscript //nologo %vbs%
if exist %vbs% del /f /q %vbs%

N.B. C:\Temp is folder where it stores the Extracted (UnZip) File.

And, c:\FolderName\batch.zip is source path, (where Zip files are stored).

Please, Change the Full File Path ( Drive, Folder & Zip file name), according to your need.

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.