[futurebasic] Re: [FB] saving file locations-make alias?

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : September 2001 : Group Archive : Group : All Groups

From: Robert Purves <robert.purves@...>
Date: Tue, 4 Sep 2001 10:10:03 +1200
>on 8/30/01 7:57 PM, Peter Dempsey at theviron@... wrote:
>
>> I know that it saves the correct name and refnum (by text checking.. which I
>> actually wrote a tiny program to do, and in game checking).  However, later
>> when trying to open the scenario (at the begining), the file can't** be
>> found (which I know from FN IsFileThere***).  I have a reload function later
>> in the program, which re-opens the last file (which would have been opened
>> while still in the program) just fine.


I haven't been following this thread closely, but converting the wdRefNum
(as returned by FB's files$ statement) into an FSSpec should solve the
immediate problem very simply,  without screeds of difficult code. The
FSSpec is permanently valid, unlike a wdRefNum.


'---Use Console mode ----
local fn MakeFSSpec( wdRefNum, fName as str63, theFSSpec as ^FSSpec )
// Given wdRefNum and file name, construct a matching FSSpec
// Returns an error code (-43 = _fnfErr) if the file does not exist
end fn = fn FSMakeFSSpec ( wdRefNum, 0, fName, #theFSSpec )

dim fName      as str63
dim @ wdRefNum as short
dim myFSSpec   as FSSpec
dim err        as OSErr
fName = files$ (_fOpen,,, wdRefNum)
long if ( fName != "" )
err = fn MakeFSSpec( wdRefNum, fName, myFSSpec )
long if ( err == _noErr )
print "FSSpec is: " myFSSpec.name " " myFSSpec.vRefNum " ";
print myFSSpec.parID
xelse
print "MakeFSSpec err = " err
end if
end if
'------------------


Once you have a file's FSSpec, there is _never_ any point in scrambling
around converting back into a wdRefNum.  wdRefNum's are obsolete. If you
know (i.e. have saved) the FSSpec, you can open the file at any later time
like this:

open "I", 1, myFSSpec.name,, myFSSpec.vRefNum, myFSSpec.parID


An alias has the advantage of giving a sporting chance of finding the file
even if someone renames or moves it (either of which will cause the above
open  statement to fail). But aliases are complicated, whereas an FSSpec is
not.

Robert P.