iOS 递归遍历文件夹及其子集下的所有文件

来源:互联网 发布:mac有类似美图秀秀 编辑:程序博客网 时间:2024/05/21 06:59

递归遍历:

//递归读取解压路径下的所有.png文件- (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:@".png"]) {                NSLog(@"%@", path);            }        }    }else{        NSLog(@"this path is not exist!");    }}


0 0
原创粉丝点击