File search with specific Extension Objective c

后端 未结 6 1499
我在风中等你
我在风中等你 2020-12-11 07:36

I am working on some file manipulation in iPhone project. Where i need to search files of specific extension. One option is to manually process each file & directory to

6条回答
  •  被撕碎了的回忆
    2020-12-11 08:19

    see using NSFileManager you can get the files and bellow the condition with you can get file with particular extension, Its work in Document Directory ..

    -(NSArray *)findFiles:(NSString *)extension
    {
        NSMutableArray *matches = [[NSMutableArray alloc]init];
        NSFileManager *manager = [NSFileManager defaultManager];
    
        NSString *item;
        NSArray *contents = [manager contentsOfDirectoryAtPath:[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] error:nil];
        for (item in contents)
        {
            if ([[item pathExtension]isEqualToString:extension])
            {
                [matches addObject:item];
            }
        }
    
        return matches;
    }
    

    use this array with your searched files.. get the return in NSArray type so use NSArray object to store this data...

    i hope this helpful to you...

提交回复
热议问题