Reputation: 37
Right now I need to loop through the content of a file,
This loop works fine and prints the content of the file
for /F %%x in (Test.txt) do @echo %%x
However because later on I want to do something else with the content I need to have more than one statement in this loop therefor I would like to use the following syntax:
for /F in (Test.txt) do
some more statements
done
Unfortunately the latter does not work? How do I get a for loop to execute multiple commands?
Upvotes: 1
Views: 841
Reputation:
To run multiple commands for a single loop, you need to enclose the commands in a parenthesised code block:
for /F %%I in (Test.txt) do (
echo %%i
echo "%%i"
echo etc
)
Be careful however as set
ting and using variables inside of a loop may require delayedexpansion
See from cmd.exe
help for:
for /?
setlocal /?
set /?
Upvotes: 1