krb
krb

Reputation: 16345

Find out the working folder in a Foundation executable?

I have a console program which is linked to the Foundation framework on Mac. How do I find out the folder the executable is in?

Upvotes: 0

Views: 74

Answers (3)

Dave DeLong
Dave DeLong

Reputation: 243156

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];

Upvotes: 4

Joshua Nozzi
Joshua Nozzi

Reputation: 61228

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.

Upvotes: 0

David Gelhar
David Gelhar

Reputation: 27900

What about [[NSBundle mainBundle] bundlePath]

Upvotes: 1

Related Questions