Computing.Net > Forums > Disk Operating System > read a file from a batch file???

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 a file from a batch file???

Reply to Message Icon

Name: pqsi
Date: May 7, 2008 at 10:53:34 Pacific
OS: xp pro
CPU/Ram: core 2
Product: dell
Comment:

I am trying to create a batch file to read a text file that will only contain either a 1 or a 0 and report it back.

Do I use the find command or???

Thank you in advance.



Sponsored Link
Ads by Google

Response Number 1
Name: DosX
Date: May 7, 2008 at 13:03:10 Pacific
Reply:

-- test.txt --
0

-- read.bat --
@ECHO OFF
FIND "1" test.txt
IF ERRORLEVEL 1 GOTO zero
IF ERRORLEVEL 0 GOTO one

:error
ECHO There was some error.
GOTO exit

:one
REM we found 1 in a file
ECHO Test.txt contains 1
GOTO exit

:zero
REM File does not contain 1, but it doesn't
REM mean it contains 0
FIND "0" test.txt
IF ERRORLEVEL 1 GOTO error
IF ERRORLEVEL 0 GOTO realzero
GOTO error

:realzero
ECHO Test.txt contains 0

:exit


0

Response Number 2
Name: pqsi
Date: May 7, 2008 at 13:30:51 Pacific
Reply:

Thanks a lot DesX :)


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







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 a file from a batch file???

A batch to read from a file? www.computing.net/answers/dos/a-batch-to-read-from-a-file/4566.html

Read file, put value to a variable www.computing.net/answers/dos/read-file-put-value-to-a-variable/13766.html

Reading text from a file www.computing.net/answers/dos/reading-text-from-a-file/9080.html