Description
This article is from the Mac Programming
FAQ, by Jon Watte h+@austin.metrowerks.com with numerous
contributions by others.
4.6) How do I get the full path of a file referenced by a vRefNum, parID and name? (Files - Mac Programming)
You don't.
OK, I cheated you. There is exactly ONE valid reason to get the full
path of a file (or folder, for that matter) and that is to display its
location to the user in, say, a settings dialog. To actually save the
location of the file you should do this: (assuming the file is in an
FSSpec called theFile - you can use FSSpecs in your program even if you
don't run under System 7; just make your own MyFSMakeFSSpec that fills
in the FSSpec manually if it's not implemented)
*code*
if ( ! aliasManagerAvailable ) { /* System 6 ? */
GetVolumeName ( theFile -> vRefNum , vName ) ;
GetVolumeModDate ( vRefNum , & date ) ;
Save ( vName , date , parID , fileName ) ;
} else {
NewAlias ( NULL , theFile , & theAlias ) ;
Save ( theAlias ) ;
DisposeHandle ( ( Handle ) theAlias ) ;
}
*end*
If you are really concerned about these issues (of course you are!) you
should save BOTH of these methods when available, and load back whatever
is there that you can handle; since users may be using your application
in a mixed System 6/System 7 environment.
To get back to the file is left as an exercise for the reader.
To open a file using fopen() or the Pascal equivalent, see above about
using and not using HSetVol.
 
Continue to:
Share and Enjoy
Bookmark this story so others can enjoy it:
Tags
os, Mac, macintosh, apple, programming, software