views:

519

answers:

2

I have read numerous articles now and it's not clear and there's lots of versions and this that and the other and I have been piecing things together and have got so far, my problem is the 'rar' command doesn't seem to accept my substition variable and instead reads it as a string.

But this is what I have

@echo off

SETLOCAL

set path=%path%;"C:\TEMP\Output"

set _sourcedir=C:\TEMP\Output

set _logfile=c:\temp\Output\zip_log.txt

set _rarpath=C:\Program Files (x86)\WinRAR

echo Starting rar batch > %_logfile%

:: Set default directory

pushd %_sourcedir%

echo Scan Directory is %_sourcedir%

FOR %%f IN (*.txt) DO (

echo %%f

%_rarpath\rar.exe a test

)

popd

ENDLOCAL

@echo on

I have cut some out and chopped it so you only get the essence, I haven't omitted any commands though.

I am trying to loop through the directory and locate all .txt files and zip em. (rar em)

The echo writes out the correct filenames.

Any ideas?

+2  A: 

I think this is your problem:

set _rarpath=C:\Program Files (x86)\WinRAR

In batch files, the environment variable delimiter is a space, so it thinks _rarpath is C:\Program

Enclose the path in double quotes and see if that helps:

set _rarpath="C:\Program Files (x86)\WinRAR"

Also, in your FOR loop change

%_rarpath\rar.exe a test

to

%_rarpath%\rar.exe a test

(or,perhaps this was a typo?)

Patrick Cuff
No it's a blatant mistake :). Thanks
Robert
Both corrections helped alot. Next is to geet the correct rar command :). I'll look into it now
Robert
A: 

I don't see where you're asking winrar to do anything with your files? %%f needs to be on the winrar command line somewhere.

Also, you shouldn't need a loop at all for this: rar.exe a test.rar %yourpath%*.csv or similar.

Mark Allen
I'm currently not asking winrar to do anything yet, all im doing is echoing the filenames for now.
Robert