Batch file and FOR /F help

G

Guest

Ok.. Have a batch file with

FOR /F "usebackq delims==" %%i IN (".\CSC_Id.txt") DO set CompName="%%i"
Echo Ready to copy %CompName%

and a file with 40 computer names in it, called "csc_id.txt" in the same
directory as the batch file. All computer names are on a sperate line (no
qoutes, no commas, no seperator) and here's the problem.
Only the last line (computername) is being picked up and used.
Anyone have any ideas??
 
P

Pegasus \(MVP\)

Bruceway said:
Ok.. Have a batch file with

FOR /F "usebackq delims==" %%i IN (".\CSC_Id.txt") DO set CompName="%%i"
Echo Ready to copy %CompName%

and a file with 40 computer names in it, called "csc_id.txt" in the same
directory as the batch file. All computer names are on a sperate line (no
qoutes, no commas, no seperator) and here's the problem.
Only the last line (computername) is being picked up and used.
Anyone have any ideas??

Your first line rattles through every line in CSC_Id.txt,
setting CompName to each computer name in turn.
When finished, CompName is set to the last name
found in CSC_Id.txt, and this is precisely what the
second line reports.

If you want the copy command to be issued for every
computer name then you must put it inside the "For" loop.
You could do it like so:

@echo off
setlocal enabledelayedexpansion
FOR /F "usebackq delims==" %%i IN (".\CSC_Id.txt") DO (
set CompName="%%i"
Echo Ready to copy !CompName!
)
endlocal
 
G

Guest

Thanks... I was being TIM (nice but dim).
It's all working with the modifications you specified...
again thanks..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top