Re: How to get non-resolved FSRef from POSIX path
Re: How to get non-resolved FSRef from POSIX path
- Subject: Re: How to get non-resolved FSRef from POSIX path
- From: "M. Uli Kusterer" <email@hidden>
- Date: Tue, 27 Jan 2004 19:46:08 +0100
You'll have to jump through some hoops. Essentially you have to get
an FSRef to the parent folder, and then build your FSRef based on
that. Below is a category on NSString I wrote for this purpose:
//
// NSStringPathFSRefUtilities.m
// Filie
//
// Created by Uli Kusterer on Tue Dec 16 2003.
// Copyright (c) 2003 M. Uli Kusterer. All rights reserved.
//
#import "NSStringPathFSRefUtilities.h"
@implementation NSString (NSStringPathFSRefUtilities)
// Thanks to Lorenzo Puleo for a working version of this idea:
-(BOOL) getFSRef: (FSRef*)outRef
{
OSStatus err;
BOOL isSymLink;
NSFileManager* manager = [NSFileManager defaultManager];
NSDictionary *sourceAttribute = [manager
fileAttributesAtPath:self traverseLink:NO];
isSymLink = ([sourceAttribute objectForKey:@"NSFileType"] ==
NSFileTypeSymbolicLink);
if(isSymLink)
{
const char* sourceParentPath;
FSRef sourceParentRef;
HFSUniStr255 sourceFileName;
sourceParentPath = (UInt8*)[[self
stringByDeletingLastPathComponent] fileSystemRepresentation];
err = FSPathMakeRef(sourceParentPath, &sourceParentRef, NULL);
if(err == noErr)
{
[[self lastPathComponent] getCharacters:sourceFileName.unicode];
sourceFileName.length = [[self lastPathComponent] length];
if (sourceFileName.length == 0)
{
err = fnfErr;
}
else
err = FSMakeFSRefUnicode( &sourceParentRef,
sourceFileName.length,
sourceFileName.unicode,
kTextEncodingFullName, outRef);
}
}
else
{
err = FSPathMakeRef([self fileSystemRepresentation], outRef, NULL);
}
return( err == noErr );
}
@end
--
Cheers,
M. Uli Kusterer
------------------------------------------------------------
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de
_______________________________________________
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.