0

How to Automatically Zip Files with a Batch File

Posted by Arch on November 25, 2019
how to automatically zip files with a batch file

If you have to do some repetitive tasks on a daily basis, you probably know how tedious it can get, especially if you have to follow multiple steps over and over again. Zipping files is definitely one of those types of tasks, but the good news is that it doesn’t have to be. There are solutions out there that will automate compressing files, and they’re done simply by creating a script file (otherwise known as a batch file) and entering some commands. Here is how to automate this process using 7-Zip and IZArc.

Downloading and Installing 7-Zip and IZArc

You can download both of these by going to their respective download pages and choosing the option that is suited to your device and operating system.

Installing 7-zip

  1. Open the .exe file you downloaded from the official site.
  2. Choose a destination folder. The default one is C:\Program files, but you can change it by clicking on the three dots.
  3. Click Install.
  4. And when the process is finished, click Close.

Installing IZArc

  1. Download the IZArc Command Line Add-On.
  2. Open the .exe file to begin the installation.
  3. Click Next.
  4. Read (or pretend to read) the License Agreement and then select “I accept the agreement”, and click Next.
  5. Choose a destination folder. The default one is in C:\Program files, but you can change it by clicking on the Browse.
  6. Click Next.
  7. Click Install.
  8. Click Finish.

Test the Installation

This is done to make sure the command prompt can find the application. If it can’t, you need to install the app again.

Path

  1. Hit the Start button and type “cmd” on your keyboard.
  2. Type “cd C:\Program Files\7-zip” or “cd C:\Program Files\izarc”
  3. Type “7z” or “izarcc”
  4. If it is working properly you will see something like “Usage: 7z <command>” and “Usage: izarcc <command>”.

Create or Modify Batch Files

This guide will use pre-prepared batch files. These files will compress all of the contents from the dedicated folder into a zipped archive, and include the date of compression in the archive name. It will also move the zipped archive to the storage folder, while removing the source files (optional). Zipdir will be the name of the location that contains the source files, and movedir will be the location to which the batch file will transfer the archives.

Using the Batch File with 7-zip

7zip

  1. Go to this link
  2. Copy and paste the text to Notepad.
  3. Name the file “test7ip.bat”. Replace “_.txt” with .bat by pressing right-click on the file and clicking Rename.
  4. Make two folders and name them “zipdir” and “movedir”.
  5. Modify the paths as instructed in the script.
  6. Place the files you want to compress into “zipdir”
  7. Use the command “7za a -tzip “%movedir%\%myfolder%_%TODAY%.zip” -r “%zipdir%\*.*” -mx5”
  8. “7z” begins the process of compressing the files.. “a” commands the addition of files to the compressed folder.
  9. “tzip”sets the compression folder type. The standard format is a zip file.
  10. “%movedir%\%myfolder%_%TODAY%.zip”is the name of the zipped folder.
  11. “%zipdir%\*.*”represents all the files in the “zipdir” folder ready for zipping. Files from all folders in “zipdir” are included in the zip folder.
  12. “mx5” sets the compression type to a zip mode with a compression level of five.

You can customize the batch file to suit your needs.

Using the Batch File with IZArc

  1. Go to this
  2. Copy and paste the text to Notepad.
  3. Name the file “testizarc.bat”. Replace “_.txt” with .bat by pressing right-click on the file and clicking Rename.
  4. Make two folders and name them “zipdir” and “movedir”.
  5. Modify the paths as instructed in the script.
  6. Place the files you want to compress into “zipdir”
  7. Use the command “izarcc -a -r -p -cx “%movedir%\%myfolder%_%TODAY%.zip” “%zipdir%\*.*””
  8. “Izarcc” begins the process of compressing the files.
  9. “a” moves files to the compressed folder.
  10. “r” re-applies the algorithm to all folders in zipdir.
  11. “p” saves the file paths so the folder retains the same arrangement.
  12. “cx” modifies the compression to the highest level.
  13. “%movedir%\%myfolder%_%TODAY%.zip” is the name of the zipped folder.
  14. “%zipdir%\*.*” are all the files in the “zipdir” folder ready for zipping.

That’s All There Is to It

As you can see, you don’t have to type any lines of code by yourself as there are already prepared batch files that can do the job for you. Just follow the guide exactly and you will be zipping faster than ever before!

Leave a Reply

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


Disclaimer: Some pages on this site may include an affiliate link. This does not effect our editorial in any way.