iOS递归遍历文件夹下的所有文件
作者:
半岛夏天 | 来源:发表于
2018-10-25 23:38 被阅读37次//遍历所有.m文件
- (void)showAllFileWithPath:(NSString *) path {
NSFileManager * fileManger = [NSFileManager defaultManager];
BOOL isDir = NO;
BOOL isExist = [fileManger fileExistsAtPath:path isDirectory:&isDir];
if (isExist) {
if (isDir) {
NSArray * dirArray = [fileManger contentsOfDirectoryAtPath:path error:nil];
NSString * subPath = nil;
for (NSString * str in dirArray) {
subPath = [path stringByAppendingPathComponent:str];
BOOL issubDir = NO;
[fileManger fileExistsAtPath:subPath isDirectory:&issubDir];
[self showAllFileWithPath:subPath];
}
}else{
NSString *fileName = [[path componentsSeparatedByString:@"/"] lastObject];
if ([fileName hasSuffix:@".m"]) {
//do anything you want
}
}
}else{
NSLog(@"this path is not exist!");
}
}
本文标题:iOS递归遍历文件夹下的所有文件
本文链接:https://www.haomeiwen.com/subject/qxphtqtx.html
网友评论