4

I need some help with a batch file because I am stumped on WinRAR in Batch, as I haven't done/used it before.

Here is the TREE of my Folders including the batch file: enter image description here

  • Each RAR file has the same Directory folder name("vegies" folder).

I would like to be able to extract/copy all folders/subfolders inside of each .rar from "Example/Program_Ex/vegie" back one directory into "Example/Program_Ex/vegies" (Dont forget the folder "vegies" already exists in each RAR which I cannot change as these automatically update themselves.)

So basically with a batch file I would like to:

extract "Example/Program_Ex/vegie/random.rar" to "Example/Program_Ex/vegies"
extract "Example/Program_Ex/vegie/random2.rar" to "Example/Program_Ex/vegies"
extract "Example/Program_Ex/vegie/random3.rar" to "Example/Program_Ex/vegies"
extract "Example/Program_Ex/vegie/random4.rar" to "Example/Program_Ex/vegies"
extract "Example/Program_Ex/vegie/random5.rar" to "Example/Program_Ex/vegies"

I also am trying to not specify a drive, more or less because the batch file will be in the correct folder instead using something such as "CD" or "PATH"?

I have looked at some examples around the web and on here of coarse, but I am still unsure the best way to go about this.

The closest example I can find would be this:

@echo off

set destinationRAR=destination_winrar_file
set source=source_folder_path

"C:\Program Files\WinRAR\WinRAR.exe" a -ep1 -esh -ibck -m0 -r -t %destinationRAR% %source%

(Above from http://fredy-invayne.blogspot.com.au/2013/05/example-winrar-batch-file.html)

Can anyone help give examples on how to implement my question please?

Community
  • 1
  • 1
Burgo855
  • 248
  • 1
  • 5
  • 19
  • Do you want to copy the archives or to extract their contents? Please note that the `a` WinRAR command in your example is for *adding* files to an (either new or existing) archive. – Andriy M Apr 24 '14 at 11:43
  • Sorry @Andriy M, i have edited my question, i want to extract their contents, the bottom example above is the closest example i can find not necessarily the one i am after. Cheers. – Burgo855 Apr 24 '14 at 11:51
  • 7Zip command line is good for this job. – 09stephenb Apr 24 '14 at 13:03
  • 7-Zip support older versions of windows ? – Burgo855 Apr 24 '14 at 13:32

2 Answers2

2
@echo off
    for %%a in (
        "%~dp0Example\Program_Ex\vegie\*.rar"
    ) do unrar x "%%~fa" -w "%~dp0Example\Program_Ex" -o+

For each file in the indicated path under the folder in where the batch file is stored, extract the content of the file indicating target folder and selecting that existing files must be overwritten.

foxidrive
  • 40,353
  • 10
  • 53
  • 68
MC ND
  • 69,615
  • 8
  • 84
  • 126
1

You can extract all the archives with a single invocation of WinRAR:

"C:\Program Files\WinRAR\WinRAR.exe" x "%~dp0Program_Ex\vegie\random*.rar" "%~dp0Program_Ex\"

The last argument in the above command line specifies the target folder for all the archives. You may want to add the -o+ switch (must go just after x) to specify that all files should be overwritten:

"C:\Program Files\WinRAR\WinRAR.exe" x -o+ "%~dp0Program_Ex\vegie\random*.rar" "%~dp0Program_Ex\"

If you omit it, the archiver will ask you what to do with existing files, if any.

Andriy M
  • 76,112
  • 17
  • 94
  • 154