The following code (adapted from https://stackoverflow.com/a/21709923/711006) unzips file named "batchX.zip" kept in folder 'Zipped'
@echo off
setlocal
cd /d %~dp0
Call :UnZipFile "D:\Unzipped\" "D:\Zipped\batchX.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%
However, the file name has to be mentioned in the batch file (batchX.zip) for it to unzip the zip file.
Can we modify this batch code so that we do not need to mention the name, and any zip file placed can be unzipped?
Also, can we unzip a .rar file through a batch code?