Search code examples
windowsbatch-filecmdzip

How to zip multiple folders using Batch script


i have below Batch file script.

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

This creates zip files of all 10 folders but it creates subfolder in zip file with same name and i dont want that. direct files should be visible in zip file. is there any way to edit above script to solve this problem.


Solution

  • If I understand your issue correctly, the easiest way to perform the task is to first step into each directory, (to make it 'current'), zip everything in the current directory, (default), then step back out again.

    @For /D %%G In (*)Do @PushD "%%G"&&"%ProgramFiles%\7-Zip\7z.exe" a -tzip "..\%%G.zip" -r&PopD