2009-06-10 72 views

回答

5

尝试FSPathMakeRef:

NSString *path = @"Some... path... here"; 
FSRef f; 
OSStatus os_status = FSPathMakeRef((const UInt8 *)[path fileSystemRepresentation], &f, NULL); 

if (os_status == noErr) { 
    NSLog(@"Success"); 
} 
2

您可以使用FSPathMakeRef()使从UTF-8的C字符串路径的FSRef,您可以使用的NSString-UTF8String方法得到一个UTF-8的C字符串:

FSRef fsref; 
Boolean isDirectory; 
OSStatus result = FSPathMakeRef([myString UTF8String], &fsref, &isDirectory); 
if(result < 0) 
    // handle error 
// If successful, fsref is valid, and isDirectory is true if the given path 
// is a directory. If you don't care about that, you can instead pass NULL 
// for the third argument of FSPathMakeRef() 
1

你可以在他的一个NSString + NDCarbonUtilities类别使用此方法从弥敦道日:

- (BOOL)getFSRef:(FSRef *)aFSRef 
{ 
    return FSPathMakeRef((const UInt8 *)[self fileSystemRepresentation], aFSRef, NULL) == noErr; 
} 

欲了解更多信息,请参阅NDAlias http://homepage.mac.com/nathan_day/pages/source.xml(MIT许可)。