Question

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:

  • Main folder
    • Backup 1
    • Backup 2
    • Backup 3

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.

Was it helpful?

Solution

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

OTHER TIPS

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%\*"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top