2011-09-16 58 views

回答

5

有幾個選項使用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"]]; 
} 
+0

非常感謝您! –

+0

如何刪除MOV文件? –

+0

我會讓你在[documentation](http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Classes/NSFileManager_Class/Reference/Reference。)中自己發現這一個。 HTML)。這就是我回答這個問題時所做的一切:)。 – Joe