11 Vote

Windows Batch Script: Pack Files into ZIP-Archive

Question by Sledge | 2015-01-24 at 16:16

I am searching for a way to automatically pack some files and/or folders into a zip archive.

I have thought about a batch script. Is there any simple method to construct such a script that is able to always automatically pack the same files when executing it?

ReplyPositiveNegative
-1Best Answer1 Vote

The easiest way is to invoke a program such as 7Zip or WinRAR with your batch script - just use the program which you have already installed on your computer.

Example using 7-Zip

I will give you an example of how to control 7Zip via batch script. First, just write the following text into a file such as packt.bat and double-click on the file to execute it:

@echo off
C:\7-Zip\7z.exe a -r target.zip file1.txt file2.txt
exit;

Important when customizing this file:

  • First of all, we have to write the application path in which you have installed 7Zip. This might be "C:\Program Files\7-Zip\7z.exe", for example.
  • After that, you can pass some parameters controlling the adding to the archive. The "a" stands for "add" or "archive" and ensures that the files will be added to the archive. The "-r" is optional and makes sure that also sub directories will be added. If you do not want to include sub directories, just omit the "-r" parameter.
  • Afterwards, you can specify the file name of the archive that should be created. In the example, we are naming it "target.zip".
  • Last, we can specify a list of files and folders that should be added to the archive. In the example, we would like to add the files "file1.txt" and "file2.txt" to the archive. Single files are separated by a space, so you have to surround file names or paths containing spaces with double quotes.

Basically, working with WinRAR is the same. Here, the command can look like that: "C:\Programs\Winrar\winrar.exe a -r target.zip file1.txt file2.txt".
2015-01-25 at 11:06

ReplyPositive Negative
Reply

Related Topics

Program in ZIP-Folder

Info | 0 Comments

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.