PDA

View Full Version : How to get the current application dir path in Carbon?




vishal.chauhan
Feb 13, 2008, 11:47 PM
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.



Sayer
Feb 14, 2008, 12:11 AM
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.

gnasher729
Feb 14, 2008, 05:30 AM
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.

toddburch
Feb 14, 2008, 07:08 AM
Would argv[0] include that information?

Todd

kainjow
Feb 14, 2008, 09:08 AM
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.

vishal.chauhan
Feb 14, 2008, 11:28 PM
Thanks.
I am exactly refering to the carbon application bundle and yes
CFBundleCopyBundleURL(CFBundleGetMainBundle()) is working fine.

arjit
Oct 29, 2009, 12:34 AM
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 ?

chown33
Oct 29, 2009, 01:16 AM
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.

idelovski
Oct 29, 2009, 01:05 PM
.... is there is a function to do that ?

I use CFURLGetFSRef() to convert url to FSRef and then:
OSErr osErr = FSGetCatalogInfo (&fileFSRef, kFSCatInfoNone, NULL, NULL, NULL, &parentFSRef);

would give FSRef of parent folder.

kainjow
Oct 29, 2009, 02:17 PM
This gives me the full application path not the parent directory :( .... is there is a function to do that ?

Use CFURLCreateCopyDeletingLastPathComponent()