Link to home
Start Free TrialLog in
Avatar of jverasql
jverasql

asked on

how would I unzip zip files using a bat file?

User generated imageI 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"].
Avatar of Omar Soudani
Omar Soudani

Do you have 7zip installed in that path (C:\Program Files\7-Zip\7z.exe) ?
Avatar of jverasql

ASKER

yes
SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you all for the help.  I apologize for the delay in response.