How to Zip a Folder Using a Batch File in Windows 10

In this article, I will show you how to compress a folder with a batch file in Windows 10. For this I use 7-zip Software.

What is 7-Zip?

7-ZIP is an open source file manager that can compress folders in a variety of formats including ZIP, BZIP2, GZIP, etc. You can also use it to decompress the file. Usually it is used in the context menu of files and folders, from where you can compress or decompress folders. However, you can also zip or unzip it Command line interface. You can create a batch file and run the cmd to compress the folder.

This is why you should consider using 7-Zip:

  • Free – You don’t have to spend any money to use it.
  • High compression rate – For ZIP and GZIP formats, 7-Zip has a better compression ratio than PKZIP and WinZip.
  • Free for commercial use – 7-Zip is protected by the GNU LGPL license, which allows you to legally copy and distribute the software.
  • Localized – You can find the software in 87 languages.
  • Windows integration – 7-Zip is compatible with the Windows shell.
  • To back up – The software uses the AES-256 file encryption system.

Zip a folder with a batch file in Windows 10

  • First, download and install 7-Zip if you don’t have it on your PC.
  • Now create a batch file to compress a folder. To do this, open the Notepad app and enter the following script:
Create a batch file
Create a batch file
echo on
for /f "tokens=3,2,4 delims=/- " %%x in ("%date%") do set d=%%y%%x%%z
set data=%d%
Echo zipping...
"C:Program Files7-Zip7z.exe" a -tzip "" 
echo Done!

Let’s check out the commands used in the script above:

  • The initial lines are used to indicate the “date” for the creation of a zip name.
  • "C:Program Files7-Zip7z.exe" is the path where 7-zip is installed on your computer.
  • A command is required to add files to the output zip folder.
  • "" is the path where I want to save my archive.
  • "C:MyDocuments*.doc" is the location of the folder I want to compress.
  • I use .doc because I only want to archive DOC files from the source folder. If you need to zip all the files out of the folder, just write "C:MyDocuments".
  • After entering the script, click file > Save as an option and save it with the .Bat Extension. Just choose All file types, Add .Bat for the file name and tap on the to save Button.
Save as .bat and tap Save
Save as .Bat and tap Save
  • Now find the batch file you created and double click on it to run the zipping script. An archive folder is created in the specified location.
Compress a folder with a batch file
Zipped files

That’s it! How to compress a folder with a batch file in Windows 10. Just follow the steps and you will have zipped your folder. Hope you found this guide useful and don’t forget to check out our website for other guides too.

Continue reading:

  • How to disable WiFi in Windows 10 using CMD or Powershell
  • How to Quickly Change Zoom Background on Android
  • How to Schedule WhatsApp Messages on Your Computer