Re: NSFileManager and Resource Forks
Re: NSFileManager and Resource Forks
- Subject: Re: NSFileManager and Resource Forks
- From: Steve Christensen <email@hidden>
- Date: Tue, 26 Oct 2010 21:10:48 -0700
On Oct 26, 2010, at 7:26 PM, email@hidden wrote:
> Is there a way to write a resource fork for a file at a path?
I don't believe that NSFileManager knows about resource files, either in the resource or data fork.
You can use Resource Manager routines FSCreateResourceFile() or FSCreateResourceFork() to create a brand-new resource file or add a resource fork to an existing file, respectively.
FSRef fileRef;
if (CFURLGetFSRef((CFURLRef)[NSURL fileURLWithPath:resourceFilePath], &fileRef))
{
HFSUniStr255 resourceForkName;
FSGetResourceForkName(&resourceForkName);
if (FSCreateResourceFork(&fileRef, resourceForkName.length, resourceForkName.unicode, 0) == noErr)
{
ResFileRefNum refNum;
if (FSOpenResourceFile(fileRef, resourceForkName.length, resourceForkName.unicode, fsRdWrPerm, &refNum) == noErr)
{
// write resources here...
CloseResFile(refNum);
return YES;
}
}
}
return NO;
Note that the above is creating a resource file in the [classic] resource fork, but unless your files contain existing non-resource data in the data fork, it might be better to create a data fork-based resource file and write resources there.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden