Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File search with specific Extension Objective c

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 find. My Question is, Is there any simple way to do that ?

Thanks

like image 661
Amjad Khan Avatar asked Dec 06 '22 10:12

Amjad Khan


1 Answers

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...

like image 135
Paras Joshi Avatar answered Dec 22 '22 23:12

Paras Joshi