如何在objective-c中使用通配符表达式找到多个文件 [英] how to find multiple files with wildcard expression in objective-c

查看:193
本文介绍了如何在objective-c中使用通配符表达式找到多个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在我的Document文件夹中编写所有的* .bmp文件(或者一般的* .xyz),编写一个iPhone 3.0的SDK?

解决方案您需要使用 NSFileManager contentsOfDirectoryAtPath:error:函数。请注意,这不是遍历子目录,并且扩展不能包含

   - (NSArray *)findFiles:(NSString *)extension 
{
NSMutableArray * matches = [[NSMutableArray alloc ]在里面];
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];
}
}

返回匹配;
}


How do I get hold of all 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;
}

这篇关于如何在objective-c中使用通配符表达式找到多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆