在尝试建议的方法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.
}
答案 0 :(得分:2)
发生错误是因为您传递的是 source 类型的kCFURLPOSIXPathStyle
,但是您想从 HFS 路径创建URL。
如我的链接答案中所述,常量kCFURLHFSPathStyle
不可用,您必须将其替换为原始值1
。
if (CFURLRef url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, (CFStringRef)ttt, 1, false))