Automatically zip folders in separate archive files 7zip bat script batch processing separate folders to archive in separate zip files or 7zip files.
How to use
Zip folders in separate archive files with 7-Zip and a batch file script in Windows 11.
This productivity life hack will speed-up your work when you need to archive multiple folders.
The batch script is with the extension .bat and it will do what you tell it to.
The Bat script
File name, you can name it anything .cmd I named it _7zipall.cmd
Batch file contents, file should have the .cmd extension to be executable.
Whole _7zipall.cmd script
You try this at your own risk, no liability accepted, no support.
for /d %%n in (*) do "%ProgramFiles%\7-Zip\7z.exe" a "%%n.zip" "%%n\"
The auto zip script explained:
For each sub directory loop
for /d %%n in (*)
goes thru each sub directory where the script is saved in / executed from. Then puts the directory details in a variable / parameter to be used in the next step.
Do run CLI program
Run the 7z 7zip executable in the script – you should check your path, you might have to change this for it to work if you installed 7zip in a different directory.
7zip archive directory
a "%%n.zip" "%%n\"
When calling the 7zip executable you pass the parameters telling it to add to archive (a) in a zip file named same as the sub directory and add the current folder in the loop to the zip file. We use the %%n variable that was set earlier.
Once 7zip finishes the current zip file, the script continues to the next directory and all steps are repeated until the last sub directory is zipped.
This script does not delete the original folders used for the zip files, you can delete those if you want. This is for safety, best to to a compare at the end if at least the count of folders and zip files is equal.
The script shown in the video will look at all directories in the current folder (where the script is saved) and
For each sub-directory it will create a new .zip file and add all the files contained in that directory to it’s zip file, then it moves to the next folder until it goes thru all the folders it found.