Computing.Net > Forums > Disk Operating System > read multiple variable from file to batc

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

read multiple variable from file to batc

Reply to Message Icon

Name: jeff
Date: July 25, 2001 at 10:58:59 Pacific
Comment:

I am attempting to read multiple variables from a text file to a batch file. I need the batch to read two variables per line 1, then run code, then loop and read next two variables on line 2, line 3, etc... repeat until eof
Any help would be great.
Thanks



Sponsored Link
Ads by Google

Response Number 1
Name: lzw
Date: July 26, 2001 at 13:24:06 Pacific
Reply:

would that be microsoft quick basic? different versions of basic may have different string processing ability but an approach like this:

OPEN datafile$ FOR INPUT AS #1
OPEN batchfile$ FOR OUPUT AS #2

DO WHILE NOT EOF(1)
LINE INPUT #1, a$
var1$ = MID$(a$, leftvarstart, LEN(leftvar))
var2$ = MID$(a$, rightvarstart, LEN(rightvar))
PRINT #2, "batch commands " + var1$ + " " + var2$
LOOP
CLOSE #1, #2

now don't just copy and paste that in but work out some of lower case words programmatically... for example:

datafile$ might be "C:\BATCH.DAT"
and
batchfile$ might be "C:\COMMANDS.BAT"
or you could assign those values with datafile$ = "witchever file", or have the program get them by prompting for user input, or from the command line using the basic key word COMMAND$

var1$ and var2$ are ok as they are and represent the variables you want to read and write.

lelftvarstart$ and rightvarstart$.... you determine the structure of your datafile to know these values. if you intend to use the batch file for processing files, you might have a datafile like:

C:\SOME_ANNOYING_SOUND.WAV C:\GAMEOVER.MP3
C:\BANG.WAV C:\SHOTGUN.MP3
etc......... etc........

if that is case consider making the file TAB delimited or you may need another string process routine... for example:

LINE INPUT #1, a$
leftvarstart = 1
FOR X = TO LEN(a$)
IF MID$(a$, X, 1) = " " THEN
rightvarstart = X + 1
EXIT FOR
END IF
var1$ = MID$(a$, leftvarstart, LEN(leftvar))
var2$ = MID$(a$, rightvarstart, LE (rightvar))


next you just want to write to the output file your DOS commands ("batch commands ") whatever they are, followed by your 2 variables for each line which will be the args for the DOS commands so don't forget the blank space... (+ " ")


0
Reply to Message Icon

Related Posts

See More


floppy disk(s) fail (co) Thanks Ronin & Tech G...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: read multiple variable from file to batc

reading variables from file in DOS ?? www.computing.net/answers/dos/reading-variables-from-file-in-dos-/7663.html

Set number of lines from a file to a var www.computing.net/answers/dos/set-number-of-lines-from-a-file-to-a-var/6487.html

COPY file to multiple directories www.computing.net/answers/dos/copy-file-to-multiple-directories/14518.html