First, make sure that the 7zip directory is in your path. Usually, it is located at
C:\Program Files\7-Zip
Next, write the following in batch file
Zip all files in a directory
for /f %%A in ('dir /b') do 7z a -tbzip2 "%%A.bz2" "%%A"
Zip files with a specific extension in a directory (download batch file)
for /f %%A in ('dir /b *.txt *.dat') do 7z a -tbzip2 "%%A.bz2" "%%A"
Save and run in the directory where you want to zip the files.
Here, I am compressing using bzip2 (notice the switch: –tbzip2). You can change that to
-tzip for zip
-tgz for gz
-t7z for 7z
some more examples here.
Cite as:
Saad, T. "7zip Batch Zip".
Weblog entry from
Please Make A Note.
https://pleasemakeanote.blogspot.com/2009/05/7zip-batch-zip.html?m=0
Thanks for share the code, I really like when I saw stuff like this because is very easy to get what you need, at least in international online pharmacy it makes my job easier.
ReplyDeleteHi i would like to create a batch file to run 7 zip to archive multiple directories one after the other
ReplyDeleteFolder 1
Folder 2
Folder 3
i want to create a batch file to run 7 zip to zip all these folders at night so that i can get
zipped files by morning
please help me