以编程方式从NSCachesDirectory删除文件 [英] Delete files from NSCachesDirectory programmatically
本文介绍了以编程方式从NSCachesDirectory删除文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我在我的应用程序中以编程方式下载 NSCachesDirectory
中的文件,是否也可以通过编程方式删除文件?
If I downloaded files in NSCachesDirectory
programmatically in my app, is it also possible to delete the files programmatically?
推荐答案
NSArray *myPathList = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *mainPath = [myPathList objectAtIndex:0];
mainPath = [mainPath stringByAppendingPathComponent:DirectoryName];
这里 mainPath 是文件的完整路径。
Here mainPath is Full Path of File.
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
BOOL fileExists = [fileManager fileExistsAtPath:mainPath];
if (fileExists)
{
BOOL success = [fileManager removeItemAtPath:mainPath error:&error];
if (!success) NSLog(@"Error: %@", [error localizedDescription]);
}
这篇关于以编程方式从NSCachesDirectory删除文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文