开发者

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?


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

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


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜