2009-12-23 119 views
17

我确定这是一个非常基本的问题,但我无法找到任何有关它的任何信息。使用来自[[NSBundle mainBundle] resourcePath的路径]

说我有我的文件夹中的应用程序,在一些文件夹,如:

  • MainFolder> SecondaryFolder> AppBundle.app>所有的东西

那么,我想要做的就是访问“MainFolder”中的文件。我知道我可以通过以下方式获得AppBundle的路径:

NSLog(@“%@”,[[NSBundle mainBundle] resourcePath]);

我不确定的是如何获得“MainFolder”的路径。

任何指针都会很棒!

感谢, 汤姆

回答

31

我会用-[NSString stringByDeletingLastPathComponent]两次。

NSString *bundlePath = [[NSBundle mainBundle] resourcePath]; 
NSString *secondParentPath = [[bundlePath stringByDeletingLastPathComponent] stringByDeletingLastPathComponent]; 
+0

完美!正是我需要的。 非常感谢! – 2009-12-24 13:07:33

4

我用: NSString *mainBundlePath = [[NSBundle mainBundle] bundlePath];

+0

''[[NSBundle mainBundle] bundlePath]'给你捆绑文件本身的路径,如果你想要捆绑内的路径,内容,那么它就是'[[NSBundle mainBundle] resourcePath]' – NikkyD 2015-05-13 14:03:23

相关问题