Search code examples
javabatch-fileweka

Batch File Error When Setting CLASSPATH


I have a number of weka datasets I need to run at once so I was creating a batch file to do that.

@ECHO OFF

FOR /r %%I IN (*.arff) DO (
    ECHO Running %%~nI
    SET CLASSPATH=C:\Program Files (x86)\Weka-3-6\weka.jar
    java weka.classifiers.functions.LinearRegression -t %%~nI -x 10
)

When I run the SET CLASSPATH command and the java command in a regular command line they work fine, and they also work on their own in a batch file but as soon as I nested them in a for loop, I started getting "\Weka-2-6\weka.jar was unexpected at this time" errors.

I'm not an expert in Java or in Batch file programming so forgive me if the fix is really simple but I've been up and down the internet and I haven't found any solutions to this problem. What am I doing wrong here?

Thanks for your help.


Solution

  • @ECHO OFF
    setlocal
    SET "CLASSPATH="C:\Program Files (x86)\Weka-3-6\weka.jar""
    
    FOR /r %%I IN (*.arff) DO (
        ECHO Running %%~nI
        java weka.classifiers.functions.LinearRegression -t %%~nI -x 10
    )
    endlcoal
    

    set class path can be expanded after the for loop is finished.So better defined it outside the loop.