Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

vishal.chauhan

macrumors newbie
Original poster
Feb 4, 2008
8
0
Hi All,

I am used to c and c++ stuff but I am new to the carbon framework.
I want to know how to get current directory path in carbon and how to convert thar path to a const char*.

Thanks.
 
You can still use Unixy features in a Carbon app on OS X (since OS X has a Unixy core deep down inside), just do the getcwd() call as if you were not using Carbon. Just add #include <unistd.h> and have at it.
 
Hi All,

I am used to c and c++ stuff but I am new to the carbon framework.
I want to know how to get current directory path in carbon and how to convert thar path to a const char*.

Thanks.

"Current directory path" is quite a meaningless concept in Carbon applications. Better tell us what it actually is that you want to achieve.
 
Hm, since the OP's title includes "current application dir path" I'm inclined to think he's referring to the path of his Carbon application. If so, you can use CFBundleCopyBundleURL(CFBundleGetMainBundle()) which returns a CFURLRef which points to the .app bundle.
 
Thanks.
I am exactly refering to the carbon application bundle and yes
CFBundleCopyBundleURL(CFBundleGetMainBundle()) is working fine.
 
Thanks.
I am exactly refering to the carbon application bundle and yes
CFBundleCopyBundleURL(CFBundleGetMainBundle()) is working fine.

This gives me the full application path not the parent directory :( .... is there is a function to do that ?
 
Would argv[0] include that information?

No. argv[0] typically contains the full path of the executable, but that's only a convention, not a requirement. The full path of the executable doesn't have anything to do with the current working directory. If it did, then /bin/pwd would never work.
 
.... is there is a function to do that ?

I use CFURLGetFSRef() to convert url to FSRef and then:
Code:
OSErr osErr = FSGetCatalogInfo (&fileFSRef, kFSCatInfoNone, NULL, NULL, NULL, &parentFSRef);
would give FSRef of parent folder.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.