Re: FSSpec from NSString Problems
Re: FSSpec from NSString Problems
- Subject: Re: FSSpec from NSString Problems
- From: Lorenzo Puleo <email@hidden>
- Date: Wed, 29 Jan 2003 18:00:31 +0100
Hi,
here a always routine to get the FSRef, then you can get from here the
FSSpec. This routine consider the sourceItem is a SymLink, and since you
cannot get an FSRef of a SymLink, it arrive there from its parent folder.
Please consider:
manager = [NSFileManager defaultManager];
- (OSErr)GetFSRef:(NSString*)sourceItem ref:(FSRef*)sourceRef
{
OSErr err;
BOOL isSymLink;
NSDictionary *sourceAttribute = [manager fileAttributesAtPath:sourceItem
traverseLink:NO];
isSymLink = ([sourceAttribute objectForKey:@"NSFileType"] ==
NSFileTypeSymbolicLink);
if(isSymLink){
const char *sourceParentPath;
FSRef sourceParentRef;
HFSUniStr255 sourceFileName;
sourceParentPath = (UInt8*)[[sourceItem
stringByDeletingLastPathComponent] fileSystemRepresentation];
err = FSPathMakeRef(sourceParentPath, &sourceParentRef, NULL);
if(err == noErr){
[[sourceItem lastPathComponent]
getCharacters:sourceFileName.unicode];
sourceFileName.length = [[sourceItem lastPathComponent] length];
if (sourceFileName.length == 0){
err = fnfErr;
}
else err = FSMakeFSRefUnicode(&sourceParentRef,
sourceFileName.length, sourceFileName.unicode, kTextEncodingFullName,
sourceRef);
}
}
else{
err = FSPathMakeRef([sourceItem fileSystemRepresentation],
sourceRef, NULL);
}
return err;
}
--
Lorenzo Puleo
mailto:email@hidden
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.