iOS 创建目录,复制文件,文件是否存在
2013-12-13 10:58
513 查看
#define FileName @"unKnowName" - (void)createFileDirectories { // 判断存放mid、mov的文件夹是否存在,不存在则创建对应文件夹 NSString *midPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"mid"]; NSFileManager *fileManager = [NSFileManager defaultManager]; BOOL isDir = FALSE; BOOL isDirExist = [fileManager fileExistsAtPath:midPath isDirectory:&isDir]; if(!(isDirExist && isDir)) { BOOL bCreateDir = [fileManager createDirectoryAtPath:midPath withIntermediateDirectories:YES attributes:nil error:nil]; if(!bCreateDir){ NSLog(@"Create Mid Directory Failed."); } NSLog(@"%@",midPath); } NSString *movPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"mov"]; isDir = FALSE; isDirExist = [fileManager fileExistsAtPath:movPath isDirectory:&isDir]; if(!(isDirExist && isDir)){ BOOL bCreateDir = [fileManager createDirectoryAtPath:movPath withIntermediateDirectories:YES attributes:nil error:nil]; if(!bCreateDir){ NSLog(@"Create Mov Directory Failed."); } NSLog(@"%@",movPath); } } - (void)copyItemToDocument { NSFileManager *fileManager = [NSFileManager defaultManager]; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *midPath = [[documentsDirectory stringByAppendingPathComponent:@"mid"] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.mid", FileName]]; NSString *resourcePath = [[NSBundle mainBundle] pathForResource:FileName ofType:@"mid"]; if([fileManager fileExistsAtPath:midPath] == NO && midPath && resourcePath) { [fileManager copyItemAtPath:resourcePath toPath:midPath error:nil]; } NSString *movPath = [[documentsDirectory stringByAppendingPathComponent:@"mov"] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.mov", FileName]]; resourcePath = [[NSBundle mainBundle] pathForResource:FileName ofType:@"mov"]; if([fileManager fileExistsAtPath:movPath] == NO && movPath && resourcePath) { [fileManager copyItemAtPath:resourcePath toPath:movPath error:nil]; } }
- (BOOL)fileExistWithName:(NSString *)fileName { NSFileManager *fileManager = [NSFileManager defaultManager]; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *midPath = [[documentsDirectory stringByAppendingPathComponent:@"mid"] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.mid", FileName]]; NSString *movPath = [[documentsDirectory stringByAppendingPathComponent:@"mov"] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.mov", FileName]]; return [fileManager fileExistsAtPath:midPath] && [fileManager fileExistsAtPath:movPath]; }
相关文章推荐
- 25个增强iOS应用程序性能的提示和技巧(高级篇)
- 25个增强iOS应用程序性能的提示和技巧--中级篇
- 25个增强iOS应用程序性能的提示和技巧(初级篇)
- ios开发尺寸
- iOS 二维码,条形码扫描
- 对IOS设备中UDID的一些思考
- 获取系统时间ios
- ios实现断点续传
- iOS开发中一些常见的并行处理
- ios 修改项目名称
- 已越狱的IOS设备再升级教程
- iOS 委托模式
- iOS申请真机调试证书-图文详解
- iOS开发者申请发布证书-图文详解
- 详解iOS应用程序内使用IAP/StoreKit付费、沙盒(SandBox)测试、创建测试账号流程
- iOS 使用宏 常量 报错 expected expression
- ios测试宏指令出错:“Expected identefier”
- ios6sdk 和ios7sdk 分别在ios6设备和ios7设备上的效果 对比
- ios(包括6、7)应用程序引用系统通讯录的方法 [亲测可行]
- IOS 基础入门教程