代码之家  ›  专栏  ›  技术社区  ›  Tom Irving

使用来自[[nsbundle mainbundle]resourcepath]的路径

  •  17
  • Tom Irving  · 技术社区  · 14 年前

    我相信这是一个非常基本的问题,但我找不到任何有关它的问题。

    假设我的应用程序在一个文件夹中,在其他一些文件夹中,如:

    • 主文件夹>第二个文件夹>appbundle.app>所有资料

    然后,我要做的是访问“主文件夹”中的文件。我知道我可以通过以下方式获得AppBundle的路径:

    nslog(@“%@”,[[nsbundle mainbundle]resourcepath]);

    我不确定的是如何获取“主文件夹”的路径。

    任何指针都会很棒!

    谢谢, 汤姆

    2 回复  |  直到 11 年前
        1
  •  31
  •   pix0r    14 年前

    我会用 -[NSString stringByDeletingLastPathComponent] 两次。

    NSString *bundlePath = [[NSBundle mainBundle] resourcePath];
    NSString *secondParentPath = [[bundlePath stringByDeletingLastPathComponent] stringByDeletingLastPathComponent];
    
        2
  •  4
  •   Constantine    11 年前

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