开发者

write content of nshomedirectory in array

开发者 https://www.devze.com 2023-03-04 10:33 出处:网络
I am new in iPhone programming. I would like to get the content of the NSHomeDirectory to an array. I have found this code

I am new in iPhone programming.

I would like to get the content of the NSHomeDirectory to an array.

I have found this code

NSError *error;
    NSFileManager *fileMgr = [NSFileManager defaultManager];

    // Point to Document directory
    NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];

    // Write out the contents of home directory to console
    NSLog(@"Documents directory: %@", [fileMgr contentsOfDirectoryAtPath:documentsDirectory error:&error]开发者_JAVA技巧);

    cell.textLabel.text = [NSString stringWithFormat:@"%@", [fileMgr contentsOfDirectoryAtPath:documentsDirectory error:&error]];

Could someone give me a way to put the files in an nsmutablearray?!?

please help me


Have you tried just constructing an NSMutableArray with the returned array?

NSMutableArray *files = [NSMutableArray arrayWithArray:[fileMgr contentsOfDirectoryAtPath:documentsDirectory error:&error]];

Or use mutableCopy on the returned array?

NSMutableArray *files = [[fileMgr contentsOfDirectoryAtPath:documentsDirectory error:&error] mutableCopy];
0

精彩评论

暂无评论...
验证码 换一张
取 消