Create batch to archive files using main folder name for archive name

2k views Asked by At

I am trying to create batch file and couldn't find solution anywhere on the web. I would like to archive (Winrar) folder&subfolders (eg.Folder A in C:\Temp\A). Folder A has a bunch of subfolders & files.

I am using this command :

"C:\Program Files\WinRAR\WinRAR.exe" a -esh -m5 -mt2 -r -s -t "ZZZZ.rar" 

Problem is that I would like archive to be named same as the name of the main folder (in this case folder "A" - A.rar), and archive to be send to folder C:\Temp (up one level).

2

There are 2 answers

2
Pruyque On BEST ANSWER

I don't have WinRAR, so I can't check the syntax for the rar command, but you could create a batchfile (backup.bat) like:

cd %1
"C:\Program Files\WinRAR\WinRAR.exe" a -esh -m5 -mt2 -r -s -t "..\%1.rar"
cd ..

And invoke it with

backup A

from the temp folder. That might be a start...

0
Abhay On

@echo off ( CD\ C: cd "Temp\A" ) "%programfiles%\winrar\rar" a -r "C:\ZZZZ.rar"