// 需要改变名字的旧文件路径
NSString *oldPath = @"/Users/zhangjinjiang/Desktop/ios";
NSFileManager *fileManager = [NSFileManager defaultManager];
// 创建一个新的文件夹路径
NSString *newPath = @"/Users/zhangjinjiang/Desktop/ios111";
[fileManager createDirectoryAtPath:newPath attributes:nil];
if ([fileManager fileExistsAtPath:oldPath]) {
NSArray *arr = [fileManager contentsOfDirectoryAtPath:oldPath error:nil];
for (NSString *fileName in arr) {
if ([fileName containsString:@"_2.png"]) {
NSString *newName = [fileName stringByReplacingOccurrencesOfString:@"_2.png" withString:@".png"];
NSData *data = [NSData dataWithContentsOfFile:[NSString stringWithFormat:@"%@/%@", oldPath, fileName]];
[fileManager createFileAtPath:[NSString stringWithFormat:@"%@/%@", newPath, newName] contents:data attributes:nil];
}
}
}