遍历目录下指定文件类型的文件,并输出

 
  [super viewDidLoad];
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSArray *path =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *file = [path objectAtIndex:0]; //获得Document系统文件目录路径
    NSDirectoryEnumerator *direnum = [fileManager enumeratorAtPath:file ]; //遍历目录
//    NSMutableArray *files = [NSMutableArray arrayWithCapacity:50];
    NSMutableArray *files = [[NSMutableArray alloc] init]; 
    NSString *fileName;
    while((fileName = [direnum nextObject])){
        if([[fileName pathExtension] isEqualToString:@"png"]){  //遍历条件
            [files addObject:fileName];
            NSLog(@"%@",fileName);
        }
    }

你可能感兴趣的:(文件)