从文档目录创建数组包括以 .MOV 结尾 [英] Creating an array from documentsDirectory includes ends with .MOV

查看:37
本文介绍了从文档目录创建数组包括以 .MOV 结尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从我的应用程序沙箱的文档目录的包含中创建一个 NSArray.它包含这么多文件,但我的数组只会以 .MOV 结尾.

I want to create a NSArray from my app sandbox's documentsDirectory's includes. It includes so many files, but my array will only be by the ones ends with .MOV.

你能帮我吗?

谢谢!

推荐答案

使用 NSFileManager 有几个选项.

NSString *path = @"<dir_path>";

//Option 1 using directory enumerator
NSDirectoryEnumerator *direnum = [[NSFileManager defaultManager] enumeratorAtPath:path];
NSMutableArray *movfiles = [NSMutableArray array];
while(NSString *file = [direnum nextObject])
{
    if([[file pathExtension] isEqualToString:@"MOV"])
        [movfiles addObject:movfiles];
}

<小时>

//Option 2 case insensitive using a predicate
NSError *error;
NSArray *dircontents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:&error];
if(error)
{
    //Handle error
}
else
{
    dircontents = [dircontents filteredArrayUsingPredicate:
                   [NSPredicate predicateWithFormat:@"pathExtension ==[c] %@", @"mov"]];
}

这篇关于从文档目录创建数组包括以 .MOV 结尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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