I have been trying for 2 days to get the superficially-simple script below working:
for /F "eol=*" %%A in (c:/users/SCTMP000/server.txt) do (echo %%A)
This itself is a reduction of my desired code, which I intended to scroll through the above text file, which is just a list of domains, in order to issue a PING
/ TRACERT
command against each domain and pipe the output to another text file. But even this simple one-liner won't process the file.
I've seen countless variations of the above cited on MSDN, StackOverflow, this site and many personal developer blogs, so feel that I'm in the right ball-park, but mine won't work ! Depending on how I render the file-name and its path (-ie quoteless, wrapped in single-quotes, wrapped in double-quotes), I see:
[quoteless] – nothing: no file open activity, and therefore no ECHO per line
[double-quoted] – the full path-name ECHOed, ie c:/users/SCTMP000/server.txt
[single-quoted] – the complete file actually opens in NotePad !!
So the path is correct, but neither the script run as a batch file, nor a command run interactively, seems to be able to actually open the text file and scroll through it. Note also that I have tried a number of the line-options: DELIMS, TOKENS, EOL etc, without success.
What am I doing wrong ? Thanks in advance.
Best Answer
I was able to get this to work with the explained results using a sample list file with domain names I placed in the list. I used the
FOR /F "USEBACKQ TOKENS=*" %%A IN ("filelist")
just like that.I try to use the
USEBACKQ
andTOKENS=*
in FOR /F loops that read from a file list for the reasons I've listed below in the Script Logic Explained section so read that over and test it to confirm.Working Batch Example
Further Resources
FOR /?