demonoid
demonoid

Reputation: 326

Zip files with same name on Windows using batch script

Let's say we have:

What I want to do is, to get zips of every eps, jpg couple with the same names like:

I can't figure out how to do this. Any suggestions?

Upvotes: 0

Views: 1986

Answers (2)

Jeff_Alieffson
Jeff_Alieffson

Reputation: 2872

Here is my example with windows native zip.exe. It looks for only *.eps files inside of current directory (because you have pair of files with the same name and different extensions), then it extracts filename, adds .eps and .jpg extensions and zip them with same name.

for /r %i in (*.eps) do zip %~ni.zip %~ni.eps %~ni.jpg

If you write inside of script then white with %%i

for /r %%i in (*.eps) do zip %%~ni.zip %%~ni.eps %%~ni.jpg

Upvotes: 1

Tural Ali
Tural Ali

Reputation: 23240

You can do it easily with help of WinRAR:

@setlocal
@echo off
set path="C:\Program Files\WinRAR\";%path%
forfiles /s /m *.jpg /C "cmd /c winrar.exe a -afzip "@fname.zip" "@fname.eps" "@fname.jpg"
pause

Upvotes: 2

Related Questions