Easy compressing and extracting using batch files

PKZIP and PKUNZIP command line utilities for handling zip files, are not the most intuitive. Instead of having to remember the proper command line parameters, for either compressing files into a zip file, or to extract the files again from a zip file, then one can put them in a batch file.

Create a batch file called ZIP.BAT containing the following lines:

@ECHO OFF
REM *** If no parameters then compress all files into ZIPFILE.ZIP
IF "%1"=="" GOTO NONAME
REM *** If one parameter(filename) then compress all files into filename
IF "%2"=="" GOTO ALL

REM *** Both filename to compress to is given and files to compress ***
PKZIP -a -ex -r -P -whs %1 %2 %3 %4 %5 %6 %7 %8 %9
GOTO EXIT

:ALL
PKZIP -a -ex -r -P -whs %1 *.*
GOTO EXIT

:NONAME
PKZIP -a -ex -r -P -whs ZIPFILE.ZIP *.*

:EXIT

Create a batch file called UZIP.BAT containing the following lines:

@ECHO OFF
REM *** If no parameters then extract all the zip files ***
IF "%1"=="" GOTO ALL
REM *** If only one parameter given then extract to current directory ***
IF "%2"=="" GOTO HERE

REM *** Two or more parameters given, the 1st is the zip file, the 2nd is the destination ***
PKUNZIP.EXE -d %1 -o %2
GOTO EXIT

:HERE
PKUNZIP.EXE -d %1 -o .\
GOTO EXIT

:ALL
PKUNZIP.EXE -d *.ZIP -o .\UZIP\

:EXIT

Updated: 2 July 2007

Comments:

  1. mark says:

    so in the case I want this to zip my files to a different folder, how do I specify that?

    Thank you.

  2. Snakefoot says:

    mark wrote:
    so in the case I want this to zip my files to a different folder, how do I specify that?

    Unless you are actually using MS DOS, then I would suggest that you use 7Zip instead of pkzip / pkunzip.

    The ZIP.BAT can take the destination of the zip-file as input argument. This will zip the files in the current directory and place the ZIP file in C:\TEMP:

    ZIP.BAT C:\TEMP\ZIPFILE.ZIP

Leave a Reply

Your email address will not be published. Required fields are marked *