-1

While trying the approach suggested here, working directory gets prefixed instead of path conversion. Leading : is HFS path does not make any difference.

    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.
    }
g-217
  • 2,069
  • 18
  • 33

1 Answers1

2

The error occurs because you are passing the source type kCFURLPOSIXPathStyle, but you want to create the URL from an HFS path.

As mentioned in my linked answer the constant kCFURLHFSPathStyle is unavailable, you have to replace it with the raw value 1.

if (CFURLRef url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, (CFStringRef)ttt, 1, false))
vadian
  • 274,689
  • 30
  • 353
  • 361
  • `kCFURLPOSIXPathStyle` = 0 is original enum, and enum definition is available and code code fails to compile with integer. – g-217 Jul 09 '19 at 10:51
  • My bad, I updated the answer. On my machine the code compiles with the integer, but the `if` expression doesn't compile. Please try the code in the linked answer literally. – vadian Jul 09 '19 at 11:05
  • Isn't this a duplicate of https://stackoverflow.com/questions/55383444/how-to-convert-a-classic-hfs-path-into-a-posix-path/? – Martin R Jul 09 '19 at 17:59
  • @MartinR Actually it is, but as the OP couldn't make to solve the issue according to the linked *here* I wrote an answer. – vadian Jul 09 '19 at 18:03