Posts: 63
Threads: 10
Joined: Jan 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.
Posts: 6,419
Threads: 74
Joined: Mar 2002
You can also check what programs are running as TSR. MEM is a program which comes with MSDOS that helps you to do so.
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.
Posts: 704
Threads: 0
Joined: Dec 2002
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.)
ravelling Curmudgeon
(geocities sites require copying and pasting URLs.)
I liked spam better when it was something that came in a can.
Windows should be defenestrated.
Posts: 63
Threads: 10
Joined: Jan 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.
BTW - besides having some great utilities, that site has one of the funniest graphics at the bottom: the file transfer thing! LOL
Posts: 704
Threads: 0
Joined: Dec 2002
.
ravelling Curmudgeon
(geocities sites require copying and pasting URLs.)
I liked spam better when it was something that came in a can.
Windows should be defenestrated.
Posts: 3,288
Threads: 167
Joined: Nov 2001
Yeah, I actually saves that "File Copy" GIF, Showed it at the office and everybody just laughed BIIG time!!!!
Posts: 704
Threads: 0
Joined: Dec 2002
that GIF instead of its usual display. (It's usually what windows ends up doing with my stuff anyway.)
ravelling Curmudgeon
(geocities sites require copying and pasting URLs.)
I liked spam better when it was something that came in a can.
Windows should be defenestrated.
Posts: 3,288
Threads: 167
Joined: Nov 2001