Create individual Zip files with a command line

Individual Zip files in a folder of files

To have WinZip Command Line Support Add-On create individual Zip files of each file in a folder, open a Command Prompt window and change directories (CD) to the folder where the files to be zipped are located.

After changing directories, you can enter the following two lines in the Command Prompt window:

path=%path%;"c:\program files\winzip"
for %f in (*.txt) do wzzip %~nf.zip %f

Or enter the following two lines in a batch file:

path=%path%;"c:\program files\winzip"
for %%f in (*.txt) do wzzip %%~nf.zip %%f

If your filenames include spaces you will need to enclose the 2nd, 3rd, and 4th variable in quotes. For the example using the Command Prompt window it would now look like this:

path=%path%;"c:\program files\winzip"
for %f in ("*.txt") do wzzip "%~nf.zip" "%f"

Individual Zip files of folders

It is also possible to create a set of Zip files where the contents of all of the subfolders in a folder will be zipped into individual Zip files. This set of commands contains a few steps and will not work directly from a command prompt. They will need to be saved in, and run from, a batch file.


REM create list of directories
CD C:\[PATH1]
DIR /AD /B >dirlist.txt

REM Zip contents of each directory
for /f "tokens=*" %%a in (dirlist.txt) do (
  CD "%%a"
  wzzip "C:\PATH2\%%a.zip"
  CD..
)


Running the commands above as a batch file, will create a text file with the name of each directory (folder) on separate lines. The second section reads the text file, changes directories to the one on the line it just read, and performs the wzzip command once for each of these lines in the text file. The [PATH1] item should be replaced with the actual path to the parent folder, which contains the subfolders you want to zip. The [PATH2] item should be replaced with the path to the target folder in which you want to save your Zip files. Other switches can be added to the wzzip command, if desired. For example, you can add "-r -p" just after wzzip if the folders have subfolders inside and you want their contents added as well.

You may want to add a command at the end of your batch file to delete the dirlist.txt file. This is optional and would depend on your preferences.

If you have trouble with or questions about this please email Technical Support.