
FB II Compiler
PG PRO
Debugging
Memory
System
Mathematics
Resources
Disk I/O
Windows
Controls
Menus
Mouse
Keyboard
Text
Fonts
Drawing
Sound
Clipboard
Printing
Communication
ASM
|
DISK I/O
Distinguish file 's alias from folder's alias
I have been using the following (modified from a routine kindly supplied by Rick Brown and possibly others) which works flawlessly and I use it in just about every application that I've written...
The routine allows me to obtain a WDRefNum% of a file, folder or volume, If I know in advance whether I'm resolving a file, folder or volume.
What I need now is to know in advance whether the alias is of a folder or volume.
Is it simply a matter of checking the returned WDRefNum% and
if it is a small negative number (say < 0 and > -100) its a volume
if it is a larger negative number (say < -100) its a folder
or is there a more elegant way of doing this.
'==============================
CLEAR LOCAL
DIM pBlk.54
DIM osErr%
LOCAL FN getWDRefNum(dirID&,volRef)
'==============================
pBlk.ioNamePtr& = 0
pBlk.ioWDDirID& = dirID&
pBlk.ioVRefNum = volRef
pBlk.ioWDProcID& = _"ERIK"
osErr% = FN OPENWD(@pBlk)
END FN = pBlk.ioVRefNum
'==============================
CLEAR LOCAL
LOCAL FN myGetWDrefNumFromAlias%(theAliasNum%, itemType%)
'===============================
DIM fSpec;0, fVrefNum%, fParID&, 63 fileName$
DIM myErr%, WDRefNum%, ParWDRefNum%
myErr% = FN useAlias(theAliasNum%,fSpec) 'pgpro fn
LONG IF myErr% = _noErr
SELECT itemType%
CASE _isFile
WDRefNum% = FN getWDRefNum(fParID&,fVrefNum%)
CASE _isFolder
PARENTID = fParID&
ParWDRefNum% = FN getWDRefNum(fParID&,fVrefNum%)
WDRefNum% = FOLDER(fileName$, ParWDRefNum%)
CASE _isDisk
WDRefNum% = FN getWDRefNum(fParID&,fVrefNum%)
END SELECT
END IF
END FN = WDRefNum%
I don't know of a way to do that in advance of actually resolving the alias. However, _after_ you've resolved the alias (which is done in the UseAlias function), then the easiest way is to look in the fParID& field of the returned fsSpec record If the fParID& equals 1, then the item is a volume (more accurately, its the volume's root directory). If the fsParID& is anything else, then the item is a file or a (non-root) directory.
If you need to distinguish between a file and a directory, then use FN GETCATINFO after you've gotten the fsSpec record. You need to set up the parameter block somewhat like this (your variable names may be different):
pb.ioVRefNum% = fVRefNum%
pb.ioDirID& = fParID&
pb.ioNamePtr& = @fileName$
pb.ioFDirIndex% = 0
See my GETCATINFO tutorial at http://www.incolor.com/rbrown/tutorials/getcatinfo.htm for details of how to call it and how to interpret the results.
I should also point out that it's possible that Apple will change the format of the fsSpec record some time in the future, in which case you may not always be able to count on fVRefNum%, fParID& and fileName$ to be in the expected positions.
You really should be using PBGetCatInfo to determine whether an item is a folder or file. Put the name of the item in ioNamePtr. Put the wdRefNum into ioVRefNum. Leave ioDirID blank (zero). The ioFlAttrib field in the returned structure will contain a set of bit flags. If bit 4 is set, then you have a folder. If not, you have a file. We probably have an example of this already written either on the Staz Software site or in the FB Examples folder that comes with FB.
|