代码之家  ›  专栏  ›  技术社区  ›  Kristina

在基础可执行文件中查找工作文件夹吗?

  •  0
  • Kristina  · 技术社区  · 15 年前

    我有一个控制台程序链接到 基础 Mac上的框架。我怎么知道 文件夹 可执行文件在吗?

    3 回复  |  直到 15 年前
        1
  •  4
  •   Dave DeLong    15 年前

    即使工具不在捆绑包中,您仍然可以使用 NSBundle 方法。例如:

    NSString * binaryPath = [[NSBundle mainBundle] executablePath];
    NSString * executableFolder = [binaryPath stringByDeletingLastPathComponent];
    
        2
  •  1
  •   David Gelhar    15 年前

    怎么样 [[NSBundle mainBundle] bundlePath]

        3
  •  0
  •   Joshua Nozzi    15 年前

    传递给main()的第一个参数( argv[0] )是可执行文件本身的路径。如果你写了这个控制台程序,你就可以这样得到它。