06. February 2010 · Comments Off on Automate Zipping Tasks using the Command-line Interface · Categories: Batch Files, Command-line Tools, Windows · Tags: Archiving Tasks, batch files
Last updated on 02/05/2022

This guide demonstrates how to automate repetitive compression tasks using batch files with two popular free archiving tools, the command-line utility for IZArc (freeware) and the standalone console version of 7-Zip (7-Zip Extra: standalone console version). For using the WinRAR command-line tools, see this post.

compression icon

Automating compression tasks using batch files or other scripting languages makes it simple and fast to compress, copy, rename, and move files from the same folder(s) when it’s necessary to do so on a regular basis.

This guide covers the use of two free archiving utilities, the command-line add-on utility for IZArc and the standalone console version for 7-Zip. Using either of these utilities to automate archiving needs is fairly easy to do, costs nothing, and saves time. Although this guide is designed to enable the user to accomplish this task quickly and easily, it is assumed that the reader is already familiar with creating and using batch files and has some experience with using compression utilities. WinXP was used to verify the information in this guide.

Step 1. Download one of the following (32 bit versions were used for this guide)

The versions used for this guide were: 7-Zip ver 18.01 (2018-01-28) for Windows:, IZArc Version 4.1, and IZArc command-line Add-On Version 1.1.

Note: This guide uses the standalone console version of 7-Zip (7za.exe), which supports only the 7z, cab, zip, gzip, bzip2, Z and the tar formats, and unpacks Z, lzma, CAB formats. The full version of 7-Zip (installable and portable versions) contains a command-line executable (7z.exe) that supports additional formats and is explained in the 7-Zip help files. 

The IZArc command-line utility creates ZIP, CAB, LHA, BH, JAR, TAR, TGZ, and TBZ formats, and extracts ZIP, RAR, ARJ, CAB, LHA(LZH), ARC, ACE, GZIP, BZIP2, TAR (TGZ, TBZ2), UUE, ZOO, JAR formats. For IZArc, the command-line executables are izarcc for the compression function and izarce for the extraction function.

Step 2. Install the utility

For 7-Zip:
Extract the 7-Zip standalone console version to a location of your choice, e.g., C:\7zipCL or C:\Program Files\7zipCL.

For IZArc:
Extract the IZArc command-line Add-on to a location of your choice or to the default location (e.g., C:\Program Files\IZArc).

Step 3. Test the installation (optional)

Open a CMD window by hitting the Start button, enter “cmd” and press “OK”. Use cd to navigate to the 7-Zip and/or IZArc installation folders and execute the following:

For 7-Zip:
Type “7za” and then press ENTER. If working correctly, you should see the usage commands for 7-zip as shown in the top left thumbnail (click the picture to enlarge):

For IZArc:
Type “izarcc” and then press ENTER. If working correctly, you should see the usage commands for IZArc as shown in the top right thumbnail (click the pictures to enlarge and view content):

Step 4. Create/modify batch file(s)

For the sake of simplicity and to focus on quickly demonstrating the use of these two compression utilities, this guide includes two simple example batch files (one for IZArc and another for 7Zip) that compresses all files from a folder into a single zip archive with a unique date suffix, moves the zip archive to another folder, and optionally deletes the original files. For both batch files, the folder “zipdir” contains the files to zip and the folder “movedir” is where the completed archives are moved.

Depending on which utility you wish to use, click one of the following links to open the batch file text in a new window where you can cut and paste it into your text editor or download it: testizarc.bat (IZArc) and/or test7zip.bat (7-Zip). Note: if you use either batch file be sure to:
remove “_.txt” from the file name to change the extension to .bat
– create the “zipdir” and “movedir” folders
– change paths as required in the script
– copy or move some files to be archived to the “zipdir” folder

Of course, either batch file can be modified to your own needs with a text editor, including changing the name or locations for the zip folder (zipdir) and move folder (movedir)

7za command for the 7-Zip batch file (test7zip.bat):

7za a -tzip "%movedir%\%myfolder%_%TODAY%.zip" -r "%zipdir%\*.*" -mx5
  • 7za – this starts the 7-Zip command-line executable.
  • a – command to add files to the archive.
  • -tzip – (optional) switch to set the type of archive. A zip file is the default compression format.
  • %movedir%\%myfolder%_%TODAY%.zip – the name of the archive to create.[“%movedir%” is the folder where the archive is to be created. “%TODAY%” is today’s date and time variable added to the zip archive name to insure a unique archive name is created each time the batch file is executed. The parentheses are optional unless there are spaces in the file path. Finally, “.zip” is the type of archive to be created.]
  • -r – (optional) recurse sub-directories
  • %zipdir%\*.* – the files and subdirs to be archived. Everything in folder “zipdir” (this includes any subfolders when using the -r switch).
  • -mx5 – (optional) switch to set compression method. In this case, it’s zip mode, compression level 5 (level 5 is normal compression which is the default level).

When using the zip format and normal compression, the optional switches can be eliminated and the command shortened as shown below:

7za a "%movedir%\%myfolder%_%TODAY%.zip" "%zipdir%\"

IZArc command for the IZArc batch file (testizarc.bat):

izarcc -a -r -p -cx "%movedir%\%myfolder%_%TODAY%.zip" "%zipdir%\*.*"
  • izarcc – starts the izarcc compression executable.
  • -a – adds files to the archive.
  • -r – (optional) recurses into subfolders (include subfolders)
  • -p – (optional) stores relative pathnames (maintains directory structure)
  • -cx – sets the compression level to maximum.
  • %movedir%\%myfolder%_%TODAY%.zip – the name of the archive to create.[“movedir” is the folder where the archive is to be created. %TODAY% is today’s date and time variable added to the zip archive name to insure that a unique archive name is created each time the batch file is executed. The parentheses are optional unless there are spaces in the file path. Finally, “.zip” is the type of archive to be created.]
  • %zipdir%\*.* – the files to be archived. In this case, it’s all the files in the folder ” zipdir” (this includes any subfolders using the “-r” command).

Currently, the IZArc help file for the IZArc program, IZArc.chm, contains limited information for the izarcc (compress) or izarce (extract) command-line functions; however, the command-line Add-on utility does include a text manual (manual.txt) that explains the commands and includes some examples for their use.

Optional switches can be eliminated and the command shortened as shown below:

izarcc -a -cx "%movedir%\%myfolder%_%TODAY%.zip" "%zipdir%\"

Using List files

Added 03/05/2013

List files are files that contain a list of one or more files and/or directories separated by new line symbols. Both the 7-Zip and IZArc command-line utilities can use list files for processing files and directories. 7-Zip uses UTF-8 encoding for list files by default, but the encoding can be changed at the command-line using the “-scs” switch if necessary (see the command-line version section in 7-zip.chm for further information).

The command-line syntax for compressing files and/or directories with a list file:

For 7-Zip:

7za a -tzip "C:\Your Folder\yourarchivename.zip @"C:\Your Folder\yourlistfile.txt"
  • 7za – the 7-Zip command-line executable.
  • a – add files to the archive command.
  • -tzip – set archive type to a zip file (optional unless using another compression format).

Note: Using list files with older versions of 7-Zip may be slow because 7-Zip will scan entire directories and/or drives of files and folders in the list file before archiving them. The issue is documented here.

For IZArc

izarcc -a -r -p -cx "C:\Your Folder\yourarchivename.zip @"C:\Your Folder\yourlistfile.txt"
  • izarcc –starts the izarcc compression executable.
  • -a – adds files to the archive.
  • -cx – sets the compression level to maximum.
  • -r – recurse into subfolders (include subfolders)
  • -p – store relative pathnames (maintains directory structure)

Examples for a list file and a batch file to illustrate using a list file with the 7-Zip and IZArc command-line utilities are below. The batch file contains commands for both utilities using a single list file. Be sure to change the file and path names as appropriate for your situation and the batch file extension to bat before using:

zip_listfile.bat

mylistfile

Summary

It’s fairly easy to automate archiving tasks using a simple batch file using either of the two free utilities covered in this guide. For basic needs, the command-line utility for IZArc or the 7-Zip standalone console version (7za.exe) should suffice. For more complex requirements, the full version of 7-Zip (7z.exe) contains additional features for more sophisticated archiving tasks from the command-line.

For more information and examples for using the 7-Zip command-line, also see the following:

Dot Net Perl’s article, 7-Zip Command-line examples

Codejacked’s article, ZIP Up Files from the command-line

The official 7-Zip Manual, 7ZIP manual & documentation

 

If you have found a spelling error, please, notify us by selecting that text and pressing Ctrl+Enter.

Print Friendly, PDF & Email
Share
profile
">Bear

Bad Behavior has blocked 1837 access attempts in the last 7 days.

Spelling error report

The following text will be sent to our editors:

home