Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

.BAT -> reading a file into a variable

Status
Not open for further replies.

AkiraKenshin

Programmer
May 18, 2005
17
CA
Basically, I wanted to read several files into the parameter for a program and instead of writing them all out in the FOR statement, I wanted to have them on a single line in another file in case i'll need to use them again.
For example:

for %%f IN (list) DO c:\program\program.exe include %%f
Where the list is taken from an external text file, say for example it read
abm.pif, profile.pif, afig.pif
and i wanted that exact line in the (list).

whats the easiest way i can accomplish this? I've heard a bit about making temp program/files but it didn't quite make sense to me. Is it also possible to have the file list them each item to a line?
 
Be a little careful here.
The lists should be single lines, and a text file.

I would script this, but this should work if all of the file extensions are identical; e.g. .txt.

Say in a folder I have three .txt files that each contain an entry such as:

bcastner
AkiraKenshin
nobody


Code:
FOR /F "tokens=1 delims= " %%i IN (*.txt) DO [b]yourcommand %%i[/b]


 
Thanks a lot, that really helped. I was actually reading the lines from a single file, but I just replaced the (list). thanks it worked nicely. Much easier than other nonsensical methods I found.
 
Actually, in case any problems arise, could you explain the parameter and tokens/delim?
 
AkiraKenshin,

/F is the filenameset tokens is the location in the file based upon your delims. in the sample you delims <delimeter> is " ". so %%i gets populated with everything up to the first " " (space).
hth
also you can type for /? at the command prompt for a more in depth explanation.
regards,
longhair
 
longhair, thanks for the clarification

however, can you explain tokens?
Also, is there a way to start from a certain CHARACTER?
say, get everything from third character to the delim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top