[futurebasic] Re: [FB] Problems reading a file [FB^3]

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : December 1999 : Group Archive : Group : All Groups

From: Rick Brown <rbrown@...>
Date: Sun, 26 Dec 1999 12:43:58 -0600

Mark Goodes wrote:

> I'm attempting to read a file using the code below.  Could someone
> please tell me why the fileSize& keeps returning 0?  Thanks.
>
> local
> dim fileName$,refNum%,fileSize&
> local fn GetFile
> fileName$=files$(_fOpen,,,refNum%)
> open "I",#1,fileName$
> fileSize&=lof(1,1)
> print fileSize&
> End fn
>
> fn GetFile

This statement:
     fileName$=files$(_fOpen,,,refNum%)
returns two pieces of information: the file's name is returned in fileName$,
and a reference number for the file's folder is returned into refNum%.

You need to specify both pieces of information when you subsequently try to
open the file.  If you specify only the file name, FB will assume that the
file is in your current default directory (your current default directory is
the same as your app's home directory, unless you explicitly change it via the
FOLDER function.  The FILES$ function does _not_ change your current default
directory).

So, it looks like what is happening is this:  In the FILES$ function you're
selecting some file that's in a different folder than your default directory.
The subsequent OPEN statement is coincidentally finding a different (empty)
file of the same name that happens to be in your default directory, and that's
the one that is being reported as having length zero.

To fix this, change your OPEN statement to say this:
     open "I",#1,fileName$,,refNum%

- Rick