Home > Mobile >  How to compress multiple directories into one 7z archive?
How to compress multiple directories into one 7z archive?

Time:07-29

I'm using the following code to compresse two hundred directories into one 7z archive, but it didn't work well for me.

for /d %%X in (*) do "c:\Program Files\7-Zip\7z.exe" a "%%X.zip" "%%X"

CodePudding user response:

You are using the name of the directory as basename for the resulting zipfile. That explains why you get multiple zipfiles instead of just one.

You can get the forloop working but this is slow and sometimes unreliable.

for /d %%X in (*) do "c:\Program Files\7-Zip\7z.exe" a "AllInFor.zip" "%%X"

Mofi's comment above is quite good but might seem a bit complex. An alternative is to use an inputfile listing the files to compress.

> dirs2zip.txt  dir /AD /S /b
"c:\Program Files\7-Zip\7z.exe" a "AllInOne.zip" @dirs2zip.txt
del dirs2zip.txt

See the documentation for the dir command and the 7-zip documentation for explanation of these commands.

  • Related