How to convert a classic HFS path into a POSIX path

后端 未结 2 1172
北海茫月
北海茫月 2020-12-22 05:55

I am reading old files that still use HFS style paths, such as VolumeName:Folder:File.

I need to convert them into POSIX paths.

I do not like to

2条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-22 06:32

    The “reverse” operation of CFURLCopyFileSystemPath() is CFURLCreateWithFileSystemPath(). Similarly as in the referenced Q&A, you have create the path style from the raw enumeration value since CFURLPathStyle.cfurlhfsPathStyle is deprecated and not available. Example:

    let hfsPath = "Macintosh HD:Applications:Xcode.app"
    if let url = CFURLCreateWithFileSystemPath(nil, hfsPath as CFString,
                                               CFURLPathStyle(rawValue: 1)!, true) as URL? {
        print(url.path) // /Applications/Xcode.app
    }
    

提交回复
热议问题