Reputation: 25
I am trying to loop through a directory with folders in it. I want to compress the folders trough 7zip (As some of them are really big files) What I mean with this is as example:
I want it so that it creates for the folders Backup 1-3 each a separate 7zip file. Here is what I got:
@echo off
set zip=7z a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on
set directory="E:\Backup\"
for /d %%i in (%directory%) do %zip% "%%i.7z" "%%i%\*"
pause
But as soon as I do it like this, it just creates 1 7zip file called Backup, it does not make a seperate 7zip file for each folder inside it.
Upvotes: 1
Views: 3532
Reputation: 41224
This is another option:
@echo off
cd /d "E:\Backup\"
set zip=7z a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on
for /d %%i in (*) do %zip% "%%i.7z" "%%i%\*"
Upvotes: 0
Reputation: 70923
You have it almost done.
@echo off
set "zip=7z a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on"
set "directory=E:\Backup"
for /d %%i in ("%directory%\*") do %zip% "%%~fi.7z" "%%~fi\*"
pause
Upvotes: 2