[futurebasic] Re: [FB] File$(_FSSpecFolder) FSSpec Info?

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : May 2008 : Group Archive : Group : All Groups

From: Robert Purves <listrp@...>
Date: Fri, 9 May 2008 12:00:59 +1200
Lake Group/Veenix Software wrote:

> First off, great job on FBtoC, it's truly incredible. Like being  
> saved from MPW all over again!

Saved by what? CodeWarrior, R.I.P.?

> One situation... in FBtoC, Files$(_FSSpecFolder) seems to return the  
> wrong values in parID and vRefNum. Correct in FB. Small sample  
> below. Do the return values need to be further interpreted, or is  
> there a work around?
>
> dim as  FSSpec      spec
> dim as  str255      name
>
> name = Files$( _FSSpecFolder, "Choose a folder",,spec )
> print "spec.name = ";spec.name, "spec.parID = ";spec.parID,  
> "spec.vRefNum = ";spec.vRefNum


A valid FSSpec for a folder may take two forms.
The canonical form has a non-null name, and the parID is the parent  
folder's dirID.
The variant form has a null name, and the parID is the folder's dirID.
The two forms are accepted as equivalents by any toolbox function that  
takes an FSSpec parameter.

The canonical form is produced by FSMakeFSSpec.
The variant form is produced, as an unexplained quirk of FB, by files$ 
( _FSSpecFolder,...)

FBtoC does not have the unexplained quirk, and so files$ 
( _FSSpecFolder,...) produces the canonical form.
I am not sure whether to regard this as an FBtoC bug (which I'll  
therefore have to fix), or to say that FB's quirk is a long standing  
bug, happily fixed in FBtoC :-)

You can convert to the null-name variant with the aid of GetFolderID,  
as shown in the demo. When run in FB, the 'conversion' harmlessly does  
nothing.

Robert P.

'-------------------
// return dirID of folder
local mode
local fn GetFolderID( folderSpec as ^FSSpec )
'~'1
dim pb.128
dim as OSErr ignore

BlockZero( pb, sizeof( pb ) )
pb.ioNamePtr& = @folderSpec.name
pb.ioVRefNum% = folderSpec.vRefNum
pb.ioDirID& = folderSpec.parID
pb.ioFDirIndex% = 0
ignore = fn PBGetCatInfoSync( @pb )
end fn = pb.ioDirID&


dim as FSSpec spec
dim as Str255 returnedName

returnedName = files$( _FSSpecFolder, "Choose a folder",, spec )
print "returnedName " returnedName
print ".name " spec.name, ".parID " spec.parID, ".vRefNum " spec.vRefNum

// construct null-name variant of FSSpec
spec.parID = fn GetFolderID( spec )
spec.name = ""

print ".name " spec.name, ".parID " spec.parID, ".vRefNum " spec.vRefNum

do
HandleEvents
until ( gFBQuit )
'---------------------