Tuesday, September 12, 2006

DOS: Using winzip for command line

You want to automate compression and you remember pkunzip.exe and pkzip.exe of yesteryear. It turns out winzip can be used from the command line and embedded into a batch (.BAT) file for automation. (oooh automated backups).

The command format is:

 winzip32 [-min] action [options] filename[.zip] file(s)


-min this specifies that WinZip should run minimized. If -min is specified, it must be the first command line parameter.

action
-a for add, -f for freshen, -u for update, and -m for move. You must specify one (and only one) of these actions. The actions correspond to the actions described in the section titled "Add dialog box options" in the online manual.

options
-r corresponds to the Include subfolders checkbox in the Add dialog and causes WinZip to add files from subfolders. Folder information is stored for files added from subfolders. If you add -p, WinZip will store folder information for all files added, not just for files from subfolders; the folder information will begin with the folder specified on the command line.

-ex, -en, -ef, -es, and -e0 determine the compression method: eXtra, Normal, Fast, Super fast, and no compression. The default is "Normal". -hs includes hidden and system files. Use -sPassword to specify a case-sensitive password. The password can be enclosed in quotes, for example, -s"Secret Password".

filename.zip
Specifies the name of the Zip file involved. Be sure to use the full filename (including the folder).

files
Is a list of one or more files, or the @ character followed by the filename containing a list of files to add, one filename per line. Wildcards (e.g. *.bak) are allowed.

examples:

 winzip32.exe -min -a -r c:\myfiles\ c:\output.zip


this creates an output.zip with all the files in the c:\myfiles\ folder. if winzip isn't in your path, you may have to use "c:\program files\winzip32.exe" instead of winzip32.exe above,

 winzip32 -a "c:\My Documents\file1.doc" c:\output2.zip


this creates an output2.zip but note how the path must be enclosed in quotation marks because there is a space in it. Also winzip32.exe and winzip32 in the 2 examples are equivalent.

source: http://www.memecode.com/docs/winzip.html

4 comments:

Anonymous said...

Excellent information. Thank you! Could you give an example of the @ option. Thanks.

ORANGE said...

hi,
thanks for the info but I am looking how to unzip files through batch files. can you help me with those with an example.

thanks.

marker said...

problem with using 'command line winzip' is that it pops up a window asked you to click on it to continue.

For a batch file you'd want to use 7zip: http://www.7zip.org (you only need 7z.exe and 7z.dll i think).

example:
7z x archive.zip

Alexis said...

At convert other type file I usually use-open damaged zip files,because this tool is very reliable in my view and it is free as far as I remember.In addition utility can too work with password-protected files.