Reputation: 890
I have a batch script which sends pings to some PCs. The available PCs are written into a text file, so each PC stands in its own line. Another batch script copies some files to the PCs (at the moment it tries to copy to all PCs).
Now I want to modify the script(s) so the batch reads out the text file and only copies to the available PCs … but how?
It should read the written lines of the text file line by line and check for EOF.
Upvotes: 3
Views: 7692
Reputation: 1071
I'm not sure what do you want, but according to your question "Read .txt line by line and put it into variables", this might be useful for you.
@echo off
setlocal enabledelayedexpansion
set count=0
for /f "tokens=*" %%x in (textfile.txt) do (
set /a count+=1
set var[!count!]=%%x
)
echo %var[4]%
pause >nul
echo %var[4]%
will print out the 4th line in textfile.txt (or any text file).
Upvotes: 8