1.

Solve : read a record of a data file in batch file?

Answer»

can some one tell me how to open a data file (text file), then read the record one at a time in MS-DOS batch file.

example,

open name.txt
:loopRead
read record %name%/end=readExit
.
.
goto loopRead
:readExit
end
you need to be more specific

how EXACTLY this file look and what you want to getname.txt file

john smith
david jackson

my batch job will read one name a time, create a letter, then go to next person. i just want to know how to use open and read commands in MS-DOS batch file, thanks.use the for loop. Quote from: dwowang on May 12, 2009, 02:41:28 PM

create a letter

What?

for /f "delims=1" %%A in ('type name.txt') do (
set /a num+=1
set %num%=%%A
if %num%==1 echo A
if %num%==2 echo B
if %num%==3 echo C
if %num%==4 echo D
if %num%==5 echo E
if %num%==6 echo F
if %num%==7 echo G
if %num%==8 echo H
if %num%==9 echo I
if %num%==10 echo J
if %num%==11 echo K
if %num%==12 echo L
if %num%==13 echo M
if %num%==14 echo N
if %num%==15 echo O
if %num%==16 echo P
if %num%==17 echo Q
if %num%==18 echo R
if %num%==19 echo S
if %num%==20 echo T
if %num%==21 echo U
if %num%==22 echo V
if %num%==23 echo W
if %num%==24 echo X
if %num%==25 echo Y
if %num%==26 echo Z
)
set num2=0
:loop
set /a num2+=1
echo %num%
if %num%==%num2% goto pause
goto loop
:pause
pause > nul

That will display the entire contents of the file (and up to 26 letters, depending on the AMOUNT of names). But you can do whatever you want witht the names.Hi Helpmeh,

You need enable delayed expansion in your code.believe or not, you just saved me 10 hrs per week at my work by using a batch file. many thanks. Quote from: dwowang on May 13, 2009, 05:43:21 PM
believe or not, you just saved me 10 hrs per week at my work by using a batch file. many thanks.
No problem


Quote from: Batcher on May 12, 2009, 09:47:19 PM
Hi Helpmeh,

You need enable delayed expansion in your code.
I can honestly say that I have no idea what that is.


Discussion

No Comment Found