Find out the working folder in a Foundation executable?
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.
精彩评论