Rps
Rps

Reputation: 21

batch programming: rar by cli, get multiple files RARed each in own archive

I'm trying to make a simple batch script but it keeps failing. I want to look for each file in a directory (basepath) and put each file in a separate rar archive.

If I use "%%~ni.rar" in the rar line, he puts all files in all archives. SO for n files i get n archives with in each archive the n files. [also he doesnt seem to put the archives in [c:\test*.*] but rather puts them in the location of the batch file.

If I use "%%i.rar" it creates two different archives, but then the filenaming is totaly wrong: f.e: testfile.jpg >> testfile.jpg.rar and thats not how i would like it (testfile.rar instead)

@ECHO OFF
CLS

SET BASEPATH=c:\test
SET RARExe=c:\PROGRA~1\WinRAR\RAR.EXE

FOR %%i IN (%basepath%\*.*) DO %RARExe% a -m0 "%%~ni.rar" c:\test\*.*
FOR %%i IN (%basepath%\) DO mkdir c:\test\%%~ni

Goto :eof

can someone help me out?

Upvotes: 2

Views: 2012

Answers (1)

Rps
Rps

Reputation: 277

I found how to do it, actually an easy solution.

FOR %%i IN (%basepath%\*.*) DO (
  rar a -ep1 -t -m0 c\test\%%~ni.rar %%i
)

Upvotes: 1

Related Questions