Description
This article is from the Mac Programming
FAQ, by Jon Watte h+@austin.metrowerks.com with numerous
contributions by others.
4.13) How do I find the folder my application started from? How do I find the application file that's running? (Files - Mac Programming)
Under System 7, you call GetProcessInformation using the
ProcessSerialNumber kCurrentProcess with a pointer to an existing FSSpec
in the parameter block. This will give you your file, and, by using the
vRefNum and parID, the folder the application is in.
*code*
OSErr CurrentProcessLocation(FSSpec *applicationSpec)
{
ProcessSerialNumber currentPSN;
ProcessInfoRec info;
currentPSN.highLongOfPSN = 0;
currentPSN.lowLongOfPSN = kCurrentProcess;
info.processInfoLength = sizeof(ProcessInfoRec);
info.processName = NULL;
info.processAppSpec = applicationSpec;
return ( GetProcessInformation(¤tPSN, &info) );
}
*end*
Beware from writing to your applications resource or data forks; the
former breaks on CDs/write protected floppies/file servers/virus
checkers, the latter fails on PowerPC as well as in the above cases.
 
Continue to:
Share and Enjoy
Bookmark this story so others can enjoy it:
Tags
os, Mac, macintosh, apple, programming, software