# Solved: batch command line rar



## lgsadmin (Oct 17, 2011)

Hi there,

I have a number of folders and I want to zip them with a command line option.

For example:
My folders are placed in c:\invoice
In this folder I have serveral other folders like 12345, 54875, 66954, etc.
These folders contains xml files. 

I want to zip each folder automatically with a batch script, so it will be 12345.zip, 54875,zip, etc.

Next I want to mail the zip files to a variabel email address, but I will open a new thread for this if my problem above is solved.

I hope someone can help me out !!
Thanks in advance.


----------



## Squashman (Apr 4, 2003)

1) Your subject thread says RAR but your explanation says ZIP which is it?
2) You didn't specify what software you are using to accomplish this?


----------



## lgsadmin (Oct 17, 2011)

Sorry Squashman, you're correct.

I've installed winrar (including the command line exe) and I would like to make a zip file.


----------



## Squashman (Apr 4, 2003)

I don't have WinRar on my computer so I am just guessing with the Winrar execution based on what I have read on the web.

Put the batch file in your Invoices directory and execute it.

```
for /D %%I in (*) do winrar a -afzip -r  %%I.zip %%I\*.*
```


----------



## lgsadmin (Oct 17, 2011)

Great, this is what I've needed, with some ajustments.
Thanks Squashman.

I will open a new thread on (maybe) a difficult question.


----------



## Squashman (Apr 4, 2003)

Thanks for marking your thread solved. If you could post the exact code you used I am sure everyone here would appreciate it.


----------



## lgsadmin (Oct 17, 2011)

Sure,

The code that I works for me is:

```
for /D %%I in (*) do "C:\Program Files\WinRAR\winrar" a -afzip -r %%I.zip %%I\*.*
```
The only thing I had to edit was the locationn of winrar with quotes because of the space in Program Files.


----------



## Squashman (Apr 4, 2003)

Yep good call.
I do something similar with Winzip but I don't have to put the path to Winzip in the batch file. I use the START command in conjunction with my Winzip command. This keep me from having to use the path because Winzip has a registry entry for something that I can't recall right now. If I didn't use the START command then I needed to use the path.

Your other option is the edit your PATH variable so that the location of Winrar exists in your PATH variable.


----------

