简体   繁体   中英

Zip files with same name on Windows using batch script

Let's say we have:

  • somedir
    • file1.eps
    • file1.jpg
    • file2.eps
    • file2.jpg

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

  • somedir
    • file1.zip
    • file2.zip

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM