- 1 year ago
7zip go down 1 directory in all folders then zip up all folders seperately
To create separate ZIP archives for each subdirectory in a directory tree using 7zip, while going down one level in each subdirectory, you can use the following batch script:
batch@echo off
setlocal
set "root_dir=C:\Path\To\Root\Directory"
set "zip_exe=C:\Path\To\7zip\7z.exe"
set "zip_password=your_password_here"
for /d /r "%root_dir%" %%D in (*) do (
pushd "%%D"
set "zip_name=%%~nxD.zip"
"%zip_exe%" a -tzip -mx9 -p"%zip_password%" "%zip_name%" ".\*"
popd
)
In this script, you need to replace the values of root_dir
, zip_exe
, and zip_password
with your own values.
The script uses a for
loop with the /d
and /r
options to recursively traverse all subdirectories of the specified root directory. For each subdirectory, it goes down one level by using the pushd
command to change the current directory to the subdirectory. It then creates a ZIP archive with 7zip, using the a
command with the -tzip
option to specify the ZIP format, the -mx9
option to set the compression level to the maximum, and the -p
option to set a password for the archive. Finally, it uses the popd
command to change the current directory back to the parent directory.
The resulting ZIP archives will be created in the same directories as the subdirectories, with each archive containing the contents of the corresponding subdirectory. Each archive will be password-protected with the password you specified.