-1

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"
Compo
  • 36,585
  • 5
  • 27
  • 39
  • What happens if you change `"%%X"` to ```"%%X\"``` and/or ```".\%%X\*"```? – Compo Jul 27 '22 at 00:02
  • I tried your method but still the same it creates multiple compress archive. The only thing that I need to compress all 2 folder into 1 compress archive that's all.. Thanks in advance... – Ryan Sevilla Jul 27 '22 at 03:38
  • 2
    Please start *7-Zip*, open the __Help__, click on first tab __Contents__ on list item __Command Line Version__ and read at least the pages __Syntax__, __Commands__ and __Switches__. There can be simply used just the command line `"%ProgramFiles%\7-Zip\7z.exe" a -bd -bso0 -mx9 -r -tzip -x!Archive.zip -- Archive.zip *` to archive everything in current directory with exception of perhaps already existing `Archive.zip` into a ZIP archive file with name `Archive.zip` using best compression. There is no `for /D` loop needed at all which does the opposite as wanted by you. – Mofi Jul 27 '22 at 07:39

1 Answers1

1

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.

OJBakker
  • 602
  • 1
  • 5
  • 6