Qbasicnews.com
Testing for existance of a file, or its content. - Printable Version

+- Qbasicnews.com (http://qbasicnews.com/newforum)
+-- Forum: QBasic (http://qbasicnews.com/newforum/forum-4.html)
+--- Forum: QB Discussion & Programming Help (http://qbasicnews.com/newforum/forum-11.html)
+--- Thread: Testing for existance of a file, or its content. (/thread-299.html)



Testing for existance of a file, or its content. - Dex4now - 02-27-2003

Hi all, this should be so simple, but I can't seem to find a command that will do it.

In QB4.5, I want to make a decision based on whether or not a file exists or something IN the file exists. Basically, (no pun intended), I want to test to see if a certain line exists in the autoexec.bat file, then branch based on whether its there or not. I can do everything except actually test the file.

Thanks all, Dex

EDIT: And to be even more specific, I'ld like to check to see whether or not DOSKEY.COM is running before taking an action.
I did find one real convoluted way to test for the existance of the autoexec.bat file:

CLS
FILES "C:\AUTOEXEC.BAT"

Insert a for/next loop here that uses the
POINT(x,y) command to test for the existence
of the letters a u t o e x c on the screen.

Told you it was convoluted! :???:


Thanks again.


Testing for existance of a file, or its content. - na_th_an - 02-27-2003

You can also check what programs are running as TSR. MEM is a program which comes with MSDOS that helps you to do so.

Code:
mem /c

will display a complete list of which TSR programs are running, so you could do this without having to hassle with AUTOEXEC.BAT

Code:
' Redirect MEM/C output to a file:
SHELL "mem /c >tsr.txt"

' Search for pattern in a file:
pattern$="doskey"
file$="tsr.txt"

found%=0    ' Not found

f%=FREEFILE
OPEN file$ FOR INPUT AS #f%
WHILE NOT EOF(f%) AND NOT found%
   LINE INPUT #f%, line$   ' Read a line from file
   IF INSTR(LCASE$(line$), LCASE$(pattern$)) THEN found%=-1
WEND
CLOSE

' tsr.txt no longer needed:

KILL "tsr.txt"

IF found% THEN PRINT "Pattern Found"

I did this in a blast. Minor corrections would be needed. Check in QB help those commands you don't know.


Inside of... - Glenn - 02-27-2003

http://www.geocities.com/gstumpff/utils.zip

is the file EXIST.FUN. It contains a QB function to do what you want. (You'll probably have to copy and paste the link to get it to work.)


Testing for existance of a file, or its content. - Dex4now - 02-27-2003

Thanks Nathan, you actually answered something else I've always wondered about but never tried. Which is, could you open a file using the OPEN and related commands on a file that wasn't created in QB.

I just was never sure if you'ld treat it as sequential or random or what.

Thanks again, Dex

Glenn - thanks to you too, we both posted at the same time. Big Grin
BTW - besides having some great utilities, that site has one of the funniest graphics at the bottom: the file transfer thing! LOL


No problem. - Glenn - 02-27-2003

.


Testing for existance of a file, or its content. - relsoft - 02-27-2003

Yeah, I actually saves that "File Copy" GIF, Showed it at the office and everybody just laughed BIIG time!!!!


I wish I could find a way to make windows use... - Glenn - 02-27-2003

that GIF instead of its usual display. (It's usually what windows ends up doing with my stuff anyway.)


Testing for existance of a file, or its content. - relsoft - 02-27-2003

LOL