Adobe Post 20210518 2041270.3138705653153072 How to Zip a Folder Using a Batch File in Windows 10

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

In this article, I will show you how to Zip a folder using a batch file in Windows 10. For this, I will 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 this 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 through the command-line interface. You can create a batch file and run the cmd to compress the folder.

Here’s why you should consider using 7-Zip:

  • Free of charge — to use it, you don’t need to spend money.
  • High compression ratio — for ZIP and GZIP formats, 7-Zip has a better compression ratio than that of PKZIP and WinZip.
  • Free for commercial use — 7-Zip is protected by the GNU LGPL license, which allows you to copy and distribute the software legally.
  • Localized — You can find the software in 87 languages.
  • Windows integration — 7-Zip is compatible with Windows Shell.
  • Secure — the software uses the AES-256 file encryption system.

Zip a folder using a batch file in Windows 10

  • Firstly, download and install 7-Zip if you don’t have it on your PC.
  • Now, create a batch file for zipping a folder. To do that, open the Notepad app and enter the below 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 Files\7-Zip\7z.exe" a -tzip "C:\twc.zip" 
"C:\MyDocuments\*.doc"
echo Done!

Let’s checkout the commands used in the above script:

  • The initial lines are used to show the “date” for creating a zip name.
  • "C:\Program Files\7-Zip\7z.exe" is the path where 7-zip is installed on your computer.
  • A command is required to add files to the output zip folder.
  • "C:\twc.zip" is the path where I want to save my archive.
  • "C:\MyDocuments\*.doc" is the location of the folder which I want to compress.
  • I used .doc because I want to archive only DOC files from the source folder. If you need to zip all files from the folder, write only "C:\MyDocuments".
  • After typing the script, click File > Save as an option and save it with the .bat extension. Simply select All file types, add .bat after the filename, and tap on the Save button.
Save as .bat and tap on Save
Save as .bat and tap on Save
  • Now, find the created batch file and double-click on it to execute the zipping script. An archive folder will be created in the specified location.
Zip a folder using a Batch file
Zipped files

That’s it! This is how to zip a folder using a batch file in Windows 10. Just follow the steps and you have your folder zipped. I hope you found this guide helpful and don’t forget to check out our site for other guides too.


Read more:

Leave a Comment

Scroll to Top

Discover more from Techschumz

Subscribe now to keep reading and get access to the full archive.

Continue reading