Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Testing for existance of a file, or its content.
#1
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.
Reply
#2
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.
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#3
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.
Reply
#4
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
Reply
#5
.
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.
Reply
#6
Yeah, I actually saves that "File Copy" GIF, Showed it at the office and everybody just laughed BIIG time!!!!
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply
#7
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.
Reply
#8
LOL
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)