2009-06-10 10 views

Antwort

5

Versuchen 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

können Sie FSPathMakeRef() verwenden, um ein FSRef von UTF-8-C-String Pfad zu machen, und Sie können die -UTF8String Methode von NSString verwenden, um ein UTF-8-C-String zu erhalten:

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

Sie diese Methode von Nathan Day verwenden kann in seiner Kategorie einer NSString + NDCarbonUtilities:

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

Weitere Informationen finden Sie unter NDAlias ​​unter http://homepage.mac.com/nathan_day/pages/source.xml (MIT Licensed).

Verwandte Themen