2009-12-23 127 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

相關問題