+(BOOL)replaceTextInDirectory:(NSString *)directoryName oldString:(NSString *)oldStr newString:(NSString *)newStr{
//1.浅遍历
NSFileManager *fm = [NSFileManagerdefaultManager];//array中的路径是相对路径
//array 的成员@“File,txt”@main.m
NSError * err = nil;
NSArray *array = [fm contentsOfDirectoryAtPath:directoryName error:&err];
if (err) {
return NO;
}
//2.过滤出TXT
BOOL b = YES;
for (NSString *pathin array) {
if ([path hasSuffix:@".txt"]) {
//3.修改txt
//全路径目录/文件名
NSString *fullPath = [[NSStringalloc]initWithFormat:@"%@/%@",directoryName,path];
b = b &&[self replaceTextInFile:fullPath oldString:oldStrnewString:newStr];
}
}
return b;
}