Batch zip multiple files with similar names

Solution 1:

See if it is this that you want, this batch file can be set up to keep the original files or delete the original files. You have to drag and drop the source folder to the batch....

DeleteOriginals.gif

KeepOriginals.gif

@echo off

:: Put the path to command line 7zip here:
set Seven=C:\Program Files\7-Zip\7z.exe

:: Delete original files "y" or "n"
set DOriginal=n
 
If exist "%~1" (IF not exist "%~1\" exit) else (exit)

setLocal EnableDelayedExpansion

Set "Folder=%~1"
pushd "%Folder%"

For /f "delims=" %%a in ('dir /b *.*') do IF not "%%~na"=="!OldName!" (
                                                                       set /a Counter+=1
                                                                       set "NameArray[!Counter!]=%%~na"
                                                                       set "OldName=%%~na"
                                                                      )

If /i "%DOriginal%"=="y" (goto :Delete) else (goto :Keep)

:Delete
For /L %%a in (1,1,%Counter%) do "%Seven%" a -tzip -sdel "!NameArray[%%a]!.zip" *"!NameArray[%%a]!"*
goto :End

:Keep
For /L %%a in (1,1,%Counter%) do "%Seven%" a -tzip "!NameArray[%%a]!.zip" *"!NameArray[%%a]!"*
goto :End

:End
echo  Bye
exit