#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];
}