开发者

Find out the working folder in a Foundation executable?

开发者 https://www.devze.com 2023-01-09 12:00 出处:网络
I have a console program whi开发者_StackOverflowch is linked to the Foundation framework on Mac. How do I find out the folder the executable is in?Even though the tool is not in a bundle, you can stil

I have a console program whi开发者_StackOverflowch is linked to the Foundation framework on Mac. How do I find out the folder the executable is in?


Even though the tool is not in a bundle, you can still use some of the NSBundle methods. For example:

NSString * binaryPath = [[NSBundle mainBundle] executablePath];
NSString * executableFolder = [binaryPath stringByDeletingLastPathComponent];


What about [[NSBundle mainBundle] bundlePath]


The first argument passed to main() ( argv[0] ) is the path to the executable itself. If you wrote said console program, you could get it that way.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号