0

I'm new in Windows batch programming and I have found problems in the variable assignment. This is my code:

@echo off
setlocal enabledelayedexpansion
set Video=1
set FILEMEDIA=outputMedia.txt
for /f %%a in (%FILEMEDIA%) do (
    set /a Video=%Video%+1
    @echo Video
    set file=%%a
    @echo file
)

If FILEMEDIA has two lines I would like to obtain Video=2 and the line in file variable. However, at the end I obtain Video=1 and an error when I tried to print file (echo is off).

1 Answer 1

1

Some kind of duplicate with How do I increment a DOS variable in a FOR /F loop?

Variables that should be delay expanded are referenced with !VARIABLE! instead of %VARIABLE%.

@echo off
setlocal enabledelayedexpansion
set Video=1
set FILEMEDIA=outputMedia.txt
for /f %%a in (%FILEMEDIA%) do (
    set /a Video+=1
    @echo !Video!
    set file=%%a
    @echo file
)
endlocal
Sign up to request clarification or add additional context in comments.

1 Comment

Maybe @echo !file! instead of @echo file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.