Praind
Praind

Reputation: 1581

For each loop not working in Batch file

I'm very new to Batch scripting so please consider that.

I'm trying to make an automated update of all SVN project folders when i log into windows.

The issue is in the for loop. I want to iterate over all path variables but it seems not to work.

Here is the code.

@echo off

set svnPath="C:\Program Files\TortoiseSVN\bin\svn.exe"
set numPaths=3

set path1=C:\projects
set path2=E:\projects\ConnectsProjects
set path3=E:\projects\CSLibs

set /P ANSWER=Would you like to synchronize with SVN? (y/n)

if /I {%ANSWER%}=={y} (
    echo --- Synchronizing with SVN repository ---

    for /L %%i in (1,1,3) do (
        %svnPath% update !path%%i!
        echo --- Updated path !path%%i! ---
    )

    echo --- Finished ---
    sleep 2
)

The problem is that the svn update command takes the parameter !path%%i! literally.

I found the syntax for this in a few google results, so it should be right shouldn't it?

Thanks for the help.

Greetings Johny

Upvotes: 0

Views: 77

Answers (1)

Stephan
Stephan

Reputation: 56188

You need

`setlocal enabledelayedexansion`.

Looking at the use of delayed variables in your if-block, I think you are aware of delayed expansion. So you just forgot that line.

for other "searchers": best put it quite after @echo off

Upvotes: 3

Related Questions