add parentheses and batch gives error
Posted: 07 Dec 2021 00:24
I have the following batch file to extract and check the last character of strings in a file:
It works as I hoped but only for the last line in the file test.txt. I'd like to have it work on every line in the file test.txt. So, I enclose commands after "do' with parentheses. Now, nothing works. I got an error message saying "@echo was unexpected at this time."
My guess is one of the variable is now empty. So, I add before the "For" command "setlocal EnableDelayedExpansion." It did not help.
I have other batch files which have several lines of commands after "do" and are enclosed with parentheses. They don't have problems. Why is this one giving the problem?
Code: Select all
@for /f "tokens=1 delims=;" %%A in ( C:\test.txt) do set d=%%A
@echo %d%
@echo %d:~-1%
@set c=%d:~-1%
@echo %c%
@if %c%==m @echo found it
My guess is one of the variable is now empty. So, I add before the "For" command "setlocal EnableDelayedExpansion." It did not help.
I have other batch files which have several lines of commands after "do" and are enclosed with parentheses. They don't have problems. Why is this one giving the problem?