How To Write A Batch File To Automatically Zip A Given Folder

Sometimes you need to backup certain collections of files or folders separately from a full backup. These are usually small configuration files that you either might not normally backup as part of a routine schedule or ones you might edit more often and need to have more frequent backups. Doing this in Windows is fairly easy by writing a batch file to execute the command-line version of 7-Zip and saving the result to a cloud-synced folder.

First, download the command-line version of 7-Zip from their website.

Extract the zip file to a folder somewhere accessible on your hard drive.

Right-click and create a new text document. This is the file we will use to create our batch commander. In Notepad, type the following command (subbing in file locations where indicated):

C:\[PATH TO 7ZIP]\7za a -y -tzip "C:\[OUTPUT PATH].zip" "C:\[INPUT PATH]" -mx5

To automatically zip all the contents of a folder, add an asterisk to the end of the input path as a wild card.

Save the document as a *.bat file (be sure to have “All File Types” selected) in a place where you can easily find it.

To run your new batch file automatically, create a new task in Windows Task Scheduler running your batch file as a program on whatever schedule you like.

2 thoughts on “How To Write A Batch File To Automatically Zip A Given Folder”

Leave a Reply