[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
<classic_kludge_code>
20010 ONERR GOTO 20050
20050 PRINT CHR$(4);"CLOSE":POKE 216,0
20055 GOSUB 10010:GOTO 30
</classic_kludge_code>
: 2) Is there a better way from a BASIC program to determine the existence
: of a file?
: I presume the answer to my second question would probably be different
: for DOS as opposed to Prodos.
Maybe, maybe not...
The tactic I have used works in both DOS and ProDOS:
200 ONERR GOTO 300
205 PRINT CHR$(4);"UNLOCK ";F$:POKE 216,0
210 PRINT CHR$(4);"OPEN ";F$:REM etc, etc, etc.
299 END : REM Jump out of the routine before you get here... 8-)
300 IF PEEK(222) <> 6 THEN 310
305 POKE 216,0:GOTO (routine to create file)
310 IF PEEK(222) = 8 THEN PRINT "I/O Error...":PRINT "Close the drive door and
press a key...":GET K$:PRINT:GOTO 205
315 PRINT "Uh-oh, something bad happened...Error #";PEEK(222);".":STOP
In DOS 3.3 you have another tactic available that is kind of neat provided
that you *know* that the file is not already open. Same routine as above,
except that you can eliminate line 210 and replace line 205 with:
205 PRINT CHR$(4);"READ ";F$:POKE 216,0
In DOS 3.3, a READ or a WRITE to a file that is not already open will
automagically OPEN the file, but if the file does not exist the file will
NOT be created. Instead an error #6 will be generated. The "gotcha" is
that if the file is already open, the READ will not reset the file
position pointer as OPEN will.
In ProDOS, if you try to READ or WRITE a file that isn't already open,
ProDOS will scream at you and tell you you can't do that.
--Dave Althoff, ][.
--
/-\ _ *** Respect rides. They do not respect you. ***
/XXX\ /X\ /X\_ _ /X\__ _ _ _____
/XXXXX\ /XXX\ _/XXXX\_ /X\ /XXXXX\ /X\ /X\ /XXXXX
_/XXXXXXX\__/XXXXX\/XXXXXXXX\_/XXX\_/XXXXXXX\__/XXX\_/XXX\_/\_/XXXXXX