0

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.

aschipfl
  • 33,626
  • 12
  • 54
  • 99
  • check this - https://stackoverflow.com/questions/28043589/how-can-i-compress-zip-and-uncompress-unzip-files-and-folders-with-bat - give me few minutes to add a script as an answer... – npocmaka Apr 23 '20 at 13:08
  • 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 that script to solve this problem. – Abhijeet Todkari Apr 23 '20 at 13:12
  • so you don't want the folder itself but only the files? – npocmaka Apr 23 '20 at 13:23
  • zip files of all 10 folder should be created separately and the above does for me but when i open that zip file there is additional folder in it with same name. and i dont want that. – Abhijeet Todkari Apr 23 '20 at 13:44

3 Answers3

1

Create a text file, and copy and paste the following:

START /W powershell Compress-Archive folder-name foldername.zip
START powershell Move-Item -Path "path-of-the-zipped-file" -Destination "path-you-want-the-file-to-be-moved-to"`

Save as zip.bat

Compo
  • 36,585
  • 5
  • 27
  • 39
1

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
Compo
  • 36,585
  • 5
  • 27
  • 39
0

check zipjs.bat. Try to put your folders in a list like in the example bellow (zipjs.bat should be in the same directory):

@echo off

set "folders_list=C:\folder1;C:\folder2;C:\folder3"
set "destination=C:\my.zip"

del "%destination%" /Q /F >nul 2>&1

for %%a in ("%folders_list%:;=";"%") do (
  if not exist "%destination%" (
    call zipjs.bat zipItem -source "%%~fa" -destination "%destination%" -force no
  ) else (
    call zipjs.bat addToZip -source  "%%~fa" -destination "%destination%" -force no
  )

)

EDIT. After some clarifications made by the OP:

@echo off

set "folders_list=C:\folder1;C:\folder2;C:\folder3"
set "destination=C:\my.zip"

del "%destination%" /Q /F >nul 2>&1

for %%a in ("%folders_list%:;=";"%") do (
  if not exist "%destination%" (
    call zipjs.bat zipDirItems -source "%%~fa" -destination "%destination%" -force no
  ) else (
    for %%# in ("%%a\*") do (
       call zipjs.bat addToZip -source  "%%~f#" -destination "%destination%" -force no
    )
  )

)
npocmaka
  • 55,367
  • 18
  • 148
  • 187