Mac Objective-C将HFS样式路径转换为POSIX路径

时间:2019-07-09 10:15:29

标签: objective-c

在尝试建议的方法here时,工作目录将被加上前缀而不是路径转换。前导:HFS路径。

    NSString * ttt = @"Macintosh HD:Users:gautam:code:Help:";
    if (CFURLRef url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, (CFStringRef)ttt, kCFURLPOSIXPathStyle, false))
    {
        NSString * posixPath = [(__bridge NSURL*)url path];
        // posixPath    __NSCFString *  "/Users/gautamjha/code/Macintosh HD:Users:gautam:code:Help:"
        const char * secondName = [posixPath UTF8String];
       // above does not help either working directory gets prefixed.
    }

1 个答案:

答案 0 :(得分:2)

发生错误是因为您传递的是 source 类型的kCFURLPOSIXPathStyle,但是您想从 HFS 路径创建URL。

如我的链接答案中所述,常量kCFURLHFSPathStyle不可用,您必须将其替换为原始值1

if (CFURLRef url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, (CFStringRef)ttt, 1, false))
相关问题