File search with specific Extension Objective c

后端 未结 6 1497
我在风中等你
我在风中等你 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:26

    Like this way you can find your specific file extension

     NSString *bundleRoot = [[NSBundle mainBundle] bundlePath];
        NSFileManager *manager = [NSFileManager defaultManager];
        NSDirectoryEnumerator *direnum = [manager enumeratorAtPath:bundleRoot];
    
        NSString *filename;
    
        while ((filename = [direnum nextObject] )) {
    
    
            if ([filename hasSuffix:@".doc"]) {   //change the suffix to what you are looking for
    
    
                [arrayListofFileName addObject:[filename stringByDeletingPathExtension]];
    
    
            }
    
        }
    

提交回复
热议问题