Saser
Saser

Reputation: 137

How do I determine which path my application is run from?

I'm creating a little program to copy the Domain file for iWeb over to a USB stick or external harddrive or such. The program is meant to be run from that USB stick or external harddrive, and then create a directory where the application is run from. E.g. the application is run from ~/Documents, the application should create a folder at ~/Documents/(account name)'s website, and then copy the Domain file to that folder. But when I try to run the application from a USB stick, it creates a folder under /, called /(account name)'s website. How do I fix this?

Upvotes: 3

Views: 564

Answers (2)

Will
Will

Reputation: 39

If you want the current working directory of your app then use NSFileManager's currentDirectoryPath.

NSString *currentPath = [[NSFileManager defaultManager] currentDirectoryPath];

Upvotes: 4

dreamlax
dreamlax

Reputation: 95315

NSBundle has an instance method called bundlePath which will almost get you what you want.

NSString *bundleParentPath = [[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent];

This should return the directory that the application is being run from.

Upvotes: 1

Related Questions