2009-06-10 53 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許可)。