[comp.sys.apple] Finding if a file exists on a disk in Applesoft BASIC.

a228arig@cdfb.utoronto (Tak Ariga) (04/19/87)

Can anyone inform me how I can find out if a given file exists on the
disk or not through a BASIC (or a ML routine) program?  I have this
simple data base program that I wrote, and I don't want to overwrite
files.

Right now, I am using VERIFY to see if the file name exists.  If it doesn't
exists (the desired case), it causes an error.  I use ONERR GOTO and use
an error handling routine to deal with it.  The problem is, it seems to
clear some GOSUB stacks, and when it encounters a RETURN, it comes back
with 'RETURN WITHOUT GOSUB ERROR', even though it was within a subroutine.
I know this is a VERY bad way of doing things, but I wrote it when I was
still in high school and knew very little of programming, and the only
way I could figure out how to do it.

I imagine I have to read the VTOC nicely, but I don't know how to do that.
Help please.  Thanks.

--Tak

-----------------------------------------------------------------------------
UUCP:     {utzoo, decvax, ihnp4, cbosgd, utcsri, mnetor}!utgpu!utcdfa!a228arig
ARPAnet:  a228arig%cdfa.toronto.edu@relay.cs.net
CSnet:    a228arig%cdfa.toronto.edu
BITNET:   a228arig@utcdfa.UTORONTO
==  University of Toronto -- Toronto, Canada  ==
-----------------------------------------------------------------------------

god3@sphinx.uchicago.edu (Peter Godwin) (04/21/87)

In article <8704190657.AA12796@cdfb.toronto.edu>, a228arig@cdfb.utoronto (Tak Ariga) writes:
> 
> Can anyone inform me how I can find out if a given file exists on the
> disk or not through a BASIC (or a ML routine) program?
> 
> Right now, I am using VERIFY to see if the file name exists.  If it doesn't
> exists (the desired case), it causes an error.  I use ONERR GOTO and use
> an error handling routine to deal with it.  The problem is, it seems to
> clear some GOSUB stacks, and when it encounters a RETURN, it comes back
> with 'RETURN WITHOUT GOSUB ERROR', even though it was within a subroutine.

There are two ways I can think of doing this.  One is obtaining an ampersand
routine &gosub &return which will maintain the stack when an error occurs.

Many utilities which make use of the ampersand vector have such a routine.

This method, however, is probably not what you want.

Another way to find a file on disk is to read the entire directory off
of the disk with a subroutine and toss the list of files into an array.

I use such a routine in a Teacher Grading program I wrote and it works well.
If you (or anyone else for that matter) would like to know how this is done,
I would be glad to put the routine on a disk if you send me one w/ return
postage.


Peter Godwin                   |      ...ihnp4!gargoyle!sphinx!god3
Univ. of Chicago Comp Ctr      |      x9.xpg@uchicago
5824 S. Kimbark Ave, #2419     |      god3%sphinx@uchicago
Chicago, IL 60637              |      Phone #: 312-288-1816 

-- 
Peter Godwin                   |      ...ihnp4!gargoyle!sphinx!god3
Univ. of Chicago Comp Ctr      |      x9.xpg@uchicago
5824 S. Kimbark Ave, #2419     |      god3%sphinx@uchicago
Chicago, IL 60637              |      Phone #: 312-288-1816 

nakada@husc4.HARVARD.EDU (paul nakada) (04/21/87)

>> Can anyone inform me how I can find out if a given file exists on the
>> disk or not through a BASIC (or a ML routine) program?
>> 
>> Right now, I am using VERIFY to see if the file name exists.  If it doesn't
>> exists (the desired case), it causes an error.  I use ONERR GOTO and use
>> an error handling routine to deal with it.  The problem is, it seems to
>> clear some GOSUB stacks, and when it encounters a RETURN, it comes back
>> with 'RETURN WITHOUT GOSUB ERROR', even though it was within a subroutine.

This problem is easily overcome using basic.  The key to it is
understanding the error handling in the apple.  The ONERR GOTO
statement is not a conditional gosub statement.  It does, although
save the current program location.  After the proper error correcting
statements are executed in the error routine (in this case, the
creation of a file) a RESUME command should be executed and not a
RETURN.  This will return to the point of the error where the error
has been corrected.  

Hope this helps...
paul nakada

nakada@husc4.harvard.edu
nakada@harvsc4.BITNET