如果我在我的应用程序中以编程方式下载了 NSCachesDirectory
中的文件,是否也可以以编程方式删除这些文件?
最佳答案
从目录中获取文件的完整路径可能有很多方法,下面是其中的一种。
NSArray *myPathList = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *mainPath = [myPathList objectAtIndex:0];
mainPath = [mainPath stringByAppendingPathComponent:DirectoryName];
这里的mainPath是文件的完整路径。
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]);
}
关于ios - 以编程方式从 NSCachesDirectory 中删除文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15064854/