Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to get non-resolved FSRef from POSIX path



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.

References: 
 >How to get non-resolved FSRef from POSIX path (From: Calvin Chen <email@hidden>)
 >Re: How to get non-resolved FSRef from POSIX path (From: Brian Webster <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.