lotus



previous page: 4.5) How do I select a folder using SFGetFile? (Files - Mac Programming)
  
page up: Mac Programming FAQ
  
next page: 4.7) What about actually getting the full path for a file? I promise I will only use it to show the location of a file to the user! (Files - Mac Programming)

4.6) How do I get the full path of a file referenced by a vRefNum, parID and name? (Files - Mac Programming)




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:















TOP
previous page: 4.5) How do I select a folder using SFGetFile? (Files - Mac Programming)
  
page up: Mac Programming FAQ
  
next page: 4.7) What about actually getting the full path for a file? I promise I will only use it to show the location of a file to the user! (Files - Mac Programming)