how would I unzip zip files using a bat file?

This shows that the path does exist. Is is the way I referencing it with the double quotes?I have this batch script, which works but now I want to add to it.

@ECHO OFF
set mydate=%date:~-4%%date:~4,2%%date:~7,2%
copy C:\Users\nabbo\*%mydate%*.zip C:\Users\nabbo\test

Using a .bat script file, how would I unzip zip files in C:\Users\nabbo\test? I found this below, but it does not work.
@echo off
setlocal

rem Define folder to process and location of 7-zip exe file
set BaseDir=C:\Users\nabbo\test\
set ZipExe=c:\Program Files\7-zip\7z.exe

rem If base directory not found quit
if not exist "%BaseDir%\" (
  echo.*ERROR* - Base directory not found [%BaseDir%].
  exit /b
)

rem If zip program not found quit
if not exist "%ZipExe%" (
  echo.*ERROR* - Zip program not found [%ZipExe%].
  exit /b
)

REM Process all zip files in folder
for %%A in ("%BaseDir%\*.zip") do (
  REM Extract desired file to destination folder
  if not exist "%BaseDir%\%%~nA" md "%BaseDir%\%%~nA"
  "%ZipExe%" e "%%~A" -o"%BaseDir%\%%~nA"
)


The error below results but the path does exist
C:\Users\nabbo>testzip.bat
The system cannot find the path specified.
*ERROR* - Zip program not found ["C:\Program Files\7-Zip\7z.exe"].
jverasqlAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

 
Omar SoudaniSystem Support EngineerCommented:
Do you have 7zip installed in that path (C:\Program Files\7-Zip\7z.exe) ?
0
 
jverasqlAuthor Commented:
yes
0
 
Bill PrewCommented:
The error seems pretty clear, it looked for the file "C:\Program Files\7-Zip\7z.exe" and that does not exist.  Double check that, including doing the following from a command prompt, it sure appears that the file may not be located there...

dir "C:\Program Files\7-Zip\7z.exe"


»bp
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
Dr. KlahnPrincipal Software EngineerCommented:
I'd use the command line pkunzip, which can be dropped in C:/Windows (no need to remember where it is) and is also easier to deal with than 7z's nonstandard command line.

However, if you stored the zip files using full file names there could be issues (which we have seen before; see the link below).

https://www.experts-exchange.com/questions/10085167/Is-there-a-command-line-PKUNZIP-supporting-LONG-Filenames.html
0
 
NVITCommented:
There is another error not yet addressed:

The system cannot find the path specified.

I would temporarily disable ECHO OFF.

Then run the bat again.
0
 
Bill PrewCommented:
I expect the following generated that error, as no files were found to copy...

copy C:\Users\nabbo\*%mydate%*.zip C:\Users\nabbo\test


»bp
0
 
jverasqlAuthor Commented:
got it to work

Dr Klahn you brought up a good point.  I got this work locally, but it was a test.  I just realized I want this work on a network where I do not know where the zip software is installed.  How would unzip all zip files in a folder not knowing where the zip software is located?
0
 
Bill PrewCommented:
Typically I would place the EXE of the unzip utility you want to use (can certainly be 7z.exe, or other...) in the same folder as the BAT script resides.  Then the BAT script can easily determine the location of the EXE since it always know where itself is located.  Something like:

set ZipExe=%~dp07z.exe

(%~dp0 will always be the path where the BAT file exists, including a trailing backslash)


»bp
0

Experts Exchange Solution brought to you by ConnectWise

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
 
Shaun VermaakTechnical Specialist/DeveloperCommented:
This is because the Program Files folder is virtualized based on which CMD.exe is executed (c:\Windows\SysWOW64\cmd.exe vs c:\Windows\System32\cmd.exe)

Copy the 7z.exe to C:\Windows\System32

PS: I would download and use 7za.exe, not 7z.exe. Seem usage here
https://www.experts-exchange.com/articles/31867/Updating-Excel-Links-in-Thousands-of-Files.html
0
 
jverasqlAuthor Commented:
Thank you all for the help.  I apologize for the delay in response.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.