Search code examples
batch-filecommandwinrar

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


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).


Solution

  • 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...