我想从我的应用程序沙箱的文件目录包含创建一个 NSArray。它包含这么多文件,但我的数组只会包含以 .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"]];
}
关于objective-c - 从documentsDirectory创建一个包含以.MOV结尾的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7447277/