
我只是希望能够删除所有sqlite文件,而无需循环浏览并查找以前版本的文件.是否有任何方法可以对removefileAtPath:方法进行通配符?
解决方法 那么,你想要删除所有* .sqlite文件?无法避免循环,但您可以通过使用nspredicate首先过滤掉非sql文件并使用快速枚举确保快速性能来限制循环.这是一种方法:- (voID)removeAllsqlitefiles { NSfileManager *manager = [NSfileManager defaultManager]; // the preferred way to get the apps documents directory NSArray *paths = NSSearchPathForDirectorIEsInDomains(NSdocumentDirectory,NSUserDomainMask,YES); Nsstring *documentsDirectory = [paths objectAtIndex:0]; // grab all the files in the documents dir NSArray *allfiles = [manager contentsOfDirectoryAtPath:documentsDirectory error:nil]; // filter the array for only sqlite files nspredicate *fltr = [nspredicate predicateWithFormat:@"self ENDSWITH '.sqlite'"]; NSArray *sqlitefiles = [allfiles filteredArrayUsingPredicate:fltr]; // use fast enumeration to iterate the array and delete the files for (Nsstring *sqlitefile in sqlitefiles) { NSError *error = nil; [manager removeItemAtPath:[documentsDirectory stringByAppendingPathComponent:sqlitefile] error:&error]; NSAssert(!error,@"Assertion: sqlite file deletion shall never throw an error."); }} 总结 以上是内存溢出为你收集整理的iOS:如何从文档目录中删除具有特定扩展名的所有现有文件?全部内容,希望文章能够帮你解决iOS:如何从文档目录中删除具有特定扩展名的所有现有文件?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)