Delete files from NSCachesDirectory programmatically

后端 未结 4 2171
南笙
南笙 2020-12-18 04:59

If I downloaded files in NSCachesDirectory programmatically in my app, is it also possible to delete the files programmatically?

4条回答
  •  南笙
    南笙 (楼主)
    2020-12-18 05:42

    I think this snippet should work for you:

    NSFileManager *fileMgr = [NSFileManager defaultManager];
    NSArray *fileArray = [fileMgr contentsOfDirectoryAtPath:directory error:nil];
    
    for (NSString *filename in fileArray)  {
        [fileMgr removeItemAtPath:[directory stringByAppendingPathComponent:filename] error:NULL];
    }
    

提交回复
热议问题