Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: currentDirectoryPath returns different paths
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: currentDirectoryPath returns different paths



On Jul 27, 2006, at 6:50 AM, <email@hidden> <email@hidden> wrote:

I use the method currentDirectoryPath to get the current location of my app.

That method doesn't return the location of your app. It returns (as its name implies) the current working directory, which is not the same thing.


When I  run the application from X Code itself i.e a build and go the
currentDirectoryPath returns the correct path say for e.g
/Users/amrit//MyApplication/build/Debug

For the same application when i go to the directory
/Users/amrit//MyApplication/build/Debug and click on the application
icon
the method currentDirectoryPath returns " / " .The same is the case if
I try to launch the application from any other directory.


Why is it so?

The current working directory varies according to how your app is launched. In addition to the above, you could open a Terminal window, use 'cd' to change the current directory, and 'open' to open your app.


How do I get the actual current working directory?

You *are* getting the correct current working directory - that's just not what you expected it to be. :-)


If what you want is the path to your app, you can use NSBundle methods:

	NSString *appPath = [[NSBundle mainBundle] executablePath];

Note that NSBundle also has a lot of methods for obtaining paths to various (possibly localized) other things inside your .app bundle. NSImage also has convenience methods for loading image resources.

sherm--

Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >currentDirectoryPath returns different paths (From: <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.