Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Using MacOS-style file paths in Cocoa?

Using MacOS-style file paths in Cocoa?
Thread Tools
Mac Enthusiast
Join Date: Sep 2001
Location: McKinney, TX
Status: Offline
Reply With Quote
Sep 28, 2001, 10:12 PM
 
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
Reply With Quote
Sep 30, 2001, 12:44 PM
 
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
Reply With Quote
Oct 3, 2001, 01:56 PM
 
You are aware that you can just cast a CFURLRef into an NSURL *, aren't you? Toll-free bridging is wonderful
     
TheBum  (op)
Mac Enthusiast
Join Date: Sep 2001
Location: McKinney, TX
Status: Offline
Reply With Quote
Oct 3, 2001, 02:08 PM
 
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
Reply With Quote
Oct 3, 2001, 03:19 PM
 
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.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 01:15 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2