Gagan_iOS Gagan_iOS - 3 years ago 352
Objective-C Question

How to get path of a folder contaning .app file in MacOSX

I have a query regarding path of a folder in Mac OSX. I have to find the current folder from where my app is executed/located.

Suppose that I have a Folder name 'ROOTFOLDER' having two files


  2. MyText.txt

Now I have to find the path of the 'ROOTFOLDER' in my code. Any idea or suggestion would be great. I am developing an enterprise Mac app.

Answer Source

NSBundle's mainBundle class method gives you an NSBundle instance for your app's bundle. Once you have that you can use the bundleURL or bundlePath properties to get the app' URL or path. Finally use NSURL or NSString path methods, for URL and path respectively, to get the parent folder.


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download