iphone - ios 查找所有保存的文件

标签 iphone ios filepath

我的应用程序不时下载大量 jpeg。所有的 jpeg 文件名都以“hmof-*.jpg”的格式保存有没有办法可以删除所有不以“hmof-”前缀开头的文件?

我显然需要在循环中执行此操作,但我不确定要循环什么。

最佳答案

像这样的……

    NSString *bundleRoot = [[NSBundle mainBundle] bundlePath];
    NSFileManager *fm = [NSFileManager defaultManager];
    NSArray *dirContents = [fm contentsOfDirectoryAtPath:bundleRoot error:nil];
    NSPredicate *fltr = [NSPredicate predicateWithFormat:@"NOT (self BEGINSWITH 'hmof-')"];
    NSArray *notHMOF = [dirContents filteredArrayUsingPredicate:fltr];

您可以使用以下方式删除文件:

for (int i=0; i<[notHMOF count]; i++) 
{       
    [fm removeItemAtPath:[NSString stringWithFormat:@"%@/%@",bundleRoot,[notHMOF objectAtIndex:i]] error:nil];
}

编辑:有效..

关于iphone - ios 查找所有保存的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10468440/

相关文章:

ios - 跳转 View Controller 链

java - 如何引用同一个jar中的资源/文件?

C++ fstream 打开

iphone - 导航 Controller 内的选项卡栏 Controller ,或共享导航 Root View

iphone - 如何从另一个 UITabBarController 中的另一个 UINavigationController 转到一个 UITabBarController 中的顶级 UINavigationController?

iOS : Scroll view works only after keyboard appears

ios - 快速滑出菜单而不滑动导航栏(以编程方式)

javascript - 为什么 &lt;script&gt; src 中的路径以单斜杠开头会导致错误?

iphone - 如何使用 XCode 4 中的 Leaks 识别泄漏对象?

iPhone SDK 6 启动带有语音导航方向的 map