How to unzip a file using the cmd? (5 Solutions!!)
Channel: Roel Van de Paar
Date: 2020-08-19

How to unzip a file using the cmd?


The Question: I want to make a BAT file that will ZIP or UNZIP a file. For zipping a file, I
have found this question: https://superuser.com/questions/110991/can-you-zip-a-
file-from-the-command-prompt-using-only-windows-built-in-capabili/112094
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

Solutions: Please watch the whole video to see all solutions, in order of how many people found them helpful

== This solution helped 10 people ==
This batch file code will help you to unzip a file.
@echo off
setlocal
cd /d %~dp0
Call :UnZipFile "C:Temp" "c:FolderNamebatch.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:FolderNamebatch.zip is source path, (where Zip files are stored).
Please, Change the Full File Path ( Drive, Folder & Zip file name), according
to your need.

== This solution helped 21 people ==
If you have Windows 10, you can use the much shorter Powershell equivalent
Expand-Archive -Force C:pathtoarchive.zip C:wheretoextractto

== This solution helped 2 people ==
ZipFile="C:UsersspvaidyaMusicfolder.zip"
ExtractTo="C:UsersspvaidyaMusic"




'If the extraction location does not exist create it.

Set fso = CreateObject("Scripting.FileSystemObject")

If NOT fso.FolderExists(ExtractTo) Then



fso.CreateFolder(ExtractTo)

End If

'Extract the contants of the zip file.

set objShell = CreateObject("Shell.Application")

set FilesInZip=objShell.NameSpace(ZipFile).items

objShell.NameSpace(ExtractTo).CopyHere(FilesInZip)

Set fso = Nothing
Set objShell = Nothing
The following vbscript can be saved as file.vbs and then run using batch script
like:
file.vbs
save this in .bat file and run it.

== This solution helped 12 people ==
On Windows 10 build 17063 or later you can use tar.exe (similar to the *nix
one). This is also available in the nanoserver docker container
C:＞ tar -xf archive.zip

With thanks & praise to God, and with thanks to the many people who have made this project possible! | Content (except music & images) licensed under cc by-sa 3.0 | Music: https://www.bensound.com/royalty-free-music | Images: https://stocksnap.io/license & others | With thanks to user venimus (https://superuser.com/users/24127), user spoorthi vaidya (https://superuser.com/users/1026976), user Rajesh S (https://superuser.com/users/711214), user np8 (https://superuser.com/users/334666), user MegaBatchGames (https://superuser.com/users/999120), user Chen Tasker (https://superuser.com/users/895397), and the Stack Exchange Network (http://superuser.com/questions/1314420). Trademarks are property of their respective owners. Disclaimer: All information is provided "AS IS" without warranty of any kind. You are responsible for your own actions. Please contact me if anything is amiss at Roel D.OT VandePaar A.T gmail.com.