开发者

how to find multiple files with wildcard expression in objective-c

开发者 https://www.devze.com 2023-02-06 06:05 出处:网络
How do I get hold of all开发者_StackOverflow the *.bmp files (or *.xyz in general) in my Document folder, writing an iPhone 3.0 SDK?You need to use NSFileManager\'s contentsOfDirectoryAtPath:error: fu

How do I get hold of all开发者_StackOverflow the *.bmp files (or *.xyz in general) in my Document folder, writing an iPhone 3.0 SDK?


You need to use NSFileManager's contentsOfDirectoryAtPath:error: function. Note that this does not traverse subdirectories and extension cannot contain a ..

-(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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号