iOS 复制文件夹下所有文件到另一个文件夹

-(void)copyFileFromPath:(NSString *)sourcePath toPath:(NSString *)toPath

{

NSFileManager *fileManager = [[NSFileManager alloc] init];

NSArray* array = [fileManager contentsOfDirectoryAtPath:sourcePath error:nil];

for(int i = 0; i<[array count]; i++)

{

NSString *fullPath = [sourcePath stringByAppendingPathComponent:[array objectAtIndex:i]];

NSString *fullToPath = [toPath stringByAppendingPathComponent:[array objectAtIndex:i]];

NSLog(@"%@",fullPath);

NSLog(@"%@",fullToPath);

//判断是不是文件夹

BOOL isFolder = NO;

//判断是不是存在路径 并且是不是文件夹

BOOL isExist = [fileManager fileExistsAtPath:fullPath isDirectory:&isFolder];

if (isExist)

{

NSError *err = nil;

[[NSFileManager defaultManager] copyItemAtPath:fullPath toPath:fullToPath error:&err];

NSLog(@"%@",err);

if (isFolder)

{

[self copyFileFromPath:fullPath toPath:fullToPath];

}

}

}

}

你可能感兴趣的:(iOS 复制文件夹下所有文件到另一个文件夹)