First, make sure that the 7zip directory is in your path. Usually, it is located at
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.