 |
 |
Using MacOS-style file paths in Cocoa?
|
 |
|
 |
|
Mac Enthusiast
Join Date: Sep 2001
Location: McKinney, TX
Status:
Offline
|
|
I'm writing a Cocoa application where I'm given file paths in MacOS format (colon-separated, with the volume name as the first component) and I need to do file operations on the corresponding files. Are there any APIs for using or converting such paths within Cocoa?
I've been attempting the brute-force method of replacing colons with slashes and vice-versa, but the volume name is giving me trouble, mainly determining the name of the boot volume for comparison. I've done extensive, frustrating searches on Apple's developer site to no avail.
Any help would be greatly appreciated.
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Mar 2000
Location: Ithaca, NY
Status:
Offline
|
|
Originally posted by TheBum:
<STRONG>I'm writing a Cocoa application where I'm given file paths in MacOS format (colon-separated, with the volume name as the first component) and I need to do file operations on the corresponding files. Are there any APIs for using or converting such paths within Cocoa?
I've been attempting the brute-force method of replacing colons with slashes and vice-versa, but the volume name is giving me trouble, mainly determining the name of the boot volume for comparison. I've done extensive, frustrating searches on Apple's developer site to no avail.
Any help would be greatly appreciated.</STRONG>
The easiest way to do this is to create a CFURL from the Carbon path, which you can then use to get the equivalent POSIX-style path. Use CFURLCreateWithFileSystemPath() with kCFURLHFSPathStyle as the path style to create the URL. Then use CFURLCopyFileSystemPath() with kCFURLPOSIXPathStyle to get a path that Cocoa can use.
|
|
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status:
Offline
|
|
You are aware that you can just cast a CFURLRef into an NSURL *, aren't you? Toll-free bridging is wonderful 
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Sep 2001
Location: McKinney, TX
Status:
Offline
|
|
Originally posted by Angus_D:
<STRONG>You are aware that you can just cast a CFURLRef into an NSURL *, aren't you? Toll-free bridging is wonderful  </STRONG>
Is that officially documented somewhere? I'm always leary of shortcuts like that if they're not documented because they could much more easily break in the next version.
|
|
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status:
Offline
|
|
Originally posted by TheBum:
<STRONG>Is that officially documented somewhere? I'm always leary of shortcuts like that if they're not documented because they could much more easily break in the next version.</STRONG>
The closest thing I found so far is this:
Core Foundation also provides "toll-free bridging" between certain services and the Cocoa's Foundation framework. Toll-free bridging enables you to substitute Cocoa objects for Core Foundation objects in function parameters and vice versa.
file:///Developer/Documentation/CoreFoundation/Overview/CFOverview/Conceptual/CFOverview-2.html
I'm sure that this will not go away or break anywhere -- they worked very hard to implement this.
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |