How to ZIP specific files from a folder using Winzip command line?

bapi picture bapi · Sep 4, 2013 · Viewed 43.1k times · Source

With this command, I'm able to ZIP all files from the folders:

wzzip.exe -a -p -r C:\DestinationPath\DataFiles_20130903.zip C:\SourcePath\*.*

But, my folder has .dat,.bat,.txt,.xls files.I want to ZIP only .dat and .bat file.How to do this?

Thanks.

Answer

r3ap3r picture r3ap3r · Sep 4, 2013

use this command (for the particular scenario in the question):

wzzip.exe -a -p -r C:\DestinationPath\DataFiles_20130903.zip C:\SourcePath\*.dat C:\SourcePath\*.bat

for more command line options for winZip refer to the following links:

winZip command line Reference 1

winZip command line Reference 2

To provide multiple file names you can also use @filename where the filename is a file which contains the list of files which you want to include in the zip file.

If you are making the command configurable then you can ask the user/ other program which is calling your command to select the file extensions and then write these selected extensions into the "filename" file using java code or any other language you prefer.

For example if the user selects bat and dat , then write "C:\SourcePath\*.bat" and "C:\SourcePath\*.dat" into the file(assume filename is fileExtensions.txt) and call the command

wzzip.exe -a -p -r "C:\DestinationPath\DataFiles_20130903.zip" @"C:\SourcePath\fileExtensions.txt"