文件操作-图片的拷贝
- (void)viewDidLoad {
[super viewDidLoad];
NSString *docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)lastObject];
NSString *lifeFilePath = [docPath stringByAppendingString:@"Life"];
NSError *errMsg = nil;
[[NSFileManager defaultManager]createDirectoryAtPath:lifeFilePath withIntermediateDirectories:YES attributes:nil error:&errMsg];
NSString *WorkFilePath = [docPath stringByAppendingString:@"Work"];
[[NSFileManager defaultManager]createDirectoryAtPath:WorkFilePath withIntermediateDirectories:YES attributes:nil error:&errMsg];
NSString *imagePath = [lifeFilePath stringByAppendingString:@"1"];
if (![[NSFileManager defaultManager]fileExistsAtPath:imagePath]) {
[[NSFileManager defaultManager]createFileAtPath:imagePath contents:nil attributes:nil];
NSData *imageData = UIImagePNGRepresentation([UIImage imageNamed:@"1"]);
[imageData writeToFile:imagePath atomically:YES];
NSError *errMsg = nil;
NSString *imagePath2 = [WorkFilePath stringByAppendingPathComponent:@"1"];
if (![[NSFileManager defaultManager] fileExistsAtPath:imagePath2]) {
[[NSFileManager defaultManager] copyItemAtPath:imagePath toPath:imagePath2 error:&errMsg];
if (errMsg) {
NSLog(@"%@",errMsg);
return;
}
}
};
NSLog(@"%@",lifeFilePath);
}