2012-07-01 102 views

回答

0

可以使用NSFileManager

下面的方法,如果沒有路徑將返回目錄的userName如果它存在,並創建它創建目錄 。

+ (NSString *)getDocsDirectoryByUserName:(NSString *)userName 
{ 

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString * documentDir = [paths objectAtIndex:0]; 
NSString * userDir = [documentDir stringByAppendingPathComponent:userName]; 

NSError *error; 
BOOL success = [[NSFileManager defaultManager] createDirectoryAtPath:userDir 
             withIntermediateDirectories:YES 
                  attributes:nil error:&error]; 

if (!success) { 
    NSLog(@"Error creating data path: %@", [error localizedDescription]); 
} 

return userDir; 
} 
相關問題