I am developing an OSX application and in it I want to know what the current directory is (i.e. the directory containing the .app file).
I am currently using the following code:
NSString *dir=[[NSFileManager defaultManager] currentDirectoryPath];
[[NSAlert alertWithMessageText:@"dir"
defaultButton:@"OK"
alternateButton:nil
otherButton:nil
informativeTextWithFormat:dir] runModal];
When launched from Xcode (Run-button), this gives me a debug directory (which is exactly what I'm looking for), but when I double-click the application in the Finder (so, in the debug directory) it gives me /, which puzzles me.
Why is this happening and how can I get the current directory with reliability?
source
share