2011-07-21 84 views
4

我的iPhone应用程序正在将照片保存到文档文件夹中。我想在使用后删除所有这些文件格式的文件夹。我知道如何在时间使用路径从iphone文档文件夹中删除多个文件?

if ([fileMgr removeItemAtPath:filePath error:&error] != YES) 
    NSLog(@"Unable to delete file: %@", [error localizedDescription]); 

删除一个文件,但我想删除所有文件中一气呵成。我所有的文件都是.png格式,我尝试了* .png但不工作。

回答

4
/* dir: the directory where your files are */ 
NSFileManager *fm = [NSFileManager defaultManager]; 
NSError *error = nil; 
NSArray *items = [fm contentsOfDirectoryAtPath:dir error:&error]; 
if (error) { /* ... */ } 

/* delete png files */ 
for (NSString *item in items) { 
    if ([[item pathExtension] isEqualToString:@"png"]) { 
     NSString *path = [dir stringByAppendingPathComponent:item]; 
     [fm removeItemAtPath:path error:&error]; 
     if (error) 
      { /* ... */ } 
    } 
} 
+0

感谢您的帮助,我只是在条件和工作后添加以下内容。 NSString * path = [documentsDirectory stringByAppendingPathComponent:item]; [fileMgr removeItemAtPath:path error:&error]; –

+0

啊,当然。对不起拉维,我错过了。 – sidyll

相关问题