[英]Program directory in Objective-C (OSX)
I'm developing an OSX-application and in it, I'd like to know what the current directory is (ie the directory which holds .app-file). 我正在开发一个OSX应用程序,在其中,我想知道当前目录是什么(即保存.app-file的目录)。
At the moment, I'm using the following code: 目前,我正在使用以下代码:
NSString *dir=[[NSFileManager defaultManager] currentDirectoryPath];
[[NSAlert alertWithMessageText:@"dir"
defaultButton:@"OK"
alternateButton:nil
otherButton:nil
informativeTextWithFormat:dir] runModal];
When running from Xcode (Run-button), this gives me the debug directory (which is what I'm looking for), but when double-clicking the app in Finder (so, in the debug directory), it's giving me /
which puzzles me. 当从Xcode(运行按钮)运行时,这给了我调试目录(这是我正在寻找的),但是当在Finder中双击应用程序时(因此,在调试目录中),它给了我/
哪个困惑我
Why does this happen and how can I get the current directory reliably? 为什么会发生这种情况?如何可靠地获取当前目录?
在Apple Swift中编程时,您将获得以下应用程序路径:
let pathtoapplication: String = NSBundle.mainBundle().bundlePath
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.