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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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 SoudaniSenior System EngineerCommented:
Do you have 7zip installed in that path (C:\Program Files\7-Zip\7z.exe) ?
0
jverasqlAuthor Commented:
yes
0
Bill PrewIT / Software Engineering ConsultantCommented:
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
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

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
NVITEnd-user supportCommented:
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 PrewIT / Software Engineering ConsultantCommented:
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 PrewIT / Software Engineering ConsultantCommented:
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

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 SpecialistCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
batfile

From novice to tech pro — start learning today.