• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Cocoa Calling Carbon Question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Cocoa Calling Carbon Question


  • Subject: Re: Cocoa Calling Carbon Question
  • From: Tom Waters <email@hidden>
  • Date: Mon, 11 Jun 2001 10:27:26 -0700

Sounds like a good entry for a FAQ:

- (BOOL)makeFSSpec:(FSSpec *)specPtr fromPath:(NSString *)inPath
{
FSRef fsref;
OSStatus status = FSPathMakeRef([inPath fileSystemRepresentation], &fsref, NULL);
if (status == noErr)
status = FSGetCatalogInfo(&fsref, kFSCatInfoNone, NULL, NULL, specPtr, NULL);
return status == noErr;
}

...

FSSpec spec;
if ([self makeFSSpec:&spec fromPath:path]) {
NSLog(@"fsspec: vol=%d parent=x name=%s", spec.vRefNum, spec.parID, &spec.name[1]);
}



On Monday, June 11, 2001, at 08:28 AM, Brian Hill wrote:

On Monday, June 11, 2001, at 09:15 AM, Stiphane Sudre wrote:

On lundi, juin 11, 2001, at 07:18 AM, Karl Goiser wrote:

Hello,

I don't know if this is a dumb question or not, but I can't work it
out. Can anybody help?


Short version:
How do I create an FSSpec from an NSString containg a full path name
(like /Users/karl/file1)?

For this kind of problem, I would have a look at the MoreFiles utilities; IIRC, they have been carbonized.


Or, in a nutshell:

Use this to convert a path to a FSRef:
(from Files.h)

extern OSStatus
FSPathMakeRef(
const UInt8 * path,
FSRef * ref,
Boolean * isDirectory); /* can be NULL */

and then this to convert the FSRef to a FSSpec:
(also from Files.h)

extern OSErr
FSGetCatalogInfo(
const FSRef * ref,
FSCatalogInfoBitmap whichInfo,
FSCatalogInfo * catalogInfo, /* can be NULL */
HFSUniStr255 * outName, /* can be NULL */
FSSpec * fsSpec, /* can be NULL */
FSRef * parentRef); /* can be NULL */

I remember seeing a way to do this via an intermediate CFURL also (on the Omni macosx-dev list), but I've found the above way to be a bit easier (YMMV).

Brian

email@hidden http://personalpages.tds.net/~brian_hill
___________________________________________________________
"Why? I came into this game for adventure - go anywhere, travel
light, get in, get out, wherever there's trouble, a man alone.
Now they've got the whole country sectioned off and you can't
move without a form. I'm the last of a breed."
-- Archibald "Harry" Tuttle, Rogue HVAC Repairman
___________________________________________________________
_______________________________________________
cocoa-dev mailing list
email@hidden
http://www.lists.apple.com/mailman/listinfo/cocoa-dev


References: 
 >Re: Cocoa Calling Carbon Question (From: Brian Hill <email@hidden>)

  • Prev by Date: Re: Swapping NSBitmapImageRep bitmapData's
  • Next by Date: Re: Accessing PostgreSQL from Cocoa apps
  • Previous by thread: Re: Cocoa Calling Carbon Question
  • Next by thread: Re: Cocoa Calling Carbon Question
  • Index(es):
    • Date
    • Thread