How can I create a batch file to compress a file or folder with Winrar?

Franklin.K.F August 8, 2010
Pinterest Stumbleupon Whatsapp

I want to convert files/folders to Winrar in different intervals by calling a batch file with a scheduler.

Can anybody help me to create the batch file, which should compress the file/folder of my choice to Winrar file? It should have the same name as the base file/folder and store the output in the same folder.

  1. William Brand
    August 9, 2010 at 12:07 am

    I'm not sure because I don't use Winrar. Might I suggest moving to 7zip, which is generally better liked? It even has an optional command line interface which should make batch files a breeze.

    Anyway, can you expand on what you want the batch to do? At some point in the process you need to tell it which files/folders to compress, so do you just want to manually input those and run the batch file to have it go through all of the ones you've entered?

    Obviously without specific information on what you want to do there's not much I can do for you. In case it helps let's make up a hypothetical situation in which you regularly add pictures to folder C:pictures and you import pictures off your camera to C:DCIM and want to currnet backups of both folders combined:
    7z a -t7z C:Backup.7z C:*.jpg
    7z a -t7z C:Backup.7z C:*.jpg

    That will scan both folders and record all .jpg files found. If you wanted to you could modify the .bat to add a date to the file name Backup.7z and then it will keep older copies and you'll have your backups done incrementally. All you have to do is install 7z and copy "7z.exe" from C:program files7zip to C:windowssystem32 (assuming C: is your main drive and you use default options).

    Personally I wouldn't even use a batch file, I find them clunky. I'd probably make a script in AutoIt just because I find them easier. I think you could even have the script run 24/7 and instruct it to execute once every night or something.

    • shrikant
      December 7, 2010 at 9:58 am

      Dear jessica
      plz tell me how to compress a folder at particular location using winrar
      for ex. i want to compress a folder D:shrikant ,to shrikant.rar using command line,which i can use in .bat file.
      plz send reply to shrimailbox@gmail.com