iOS 删除本地文件的方法
2015-12-29 13:23
357 查看
// 文件存放目录
NSString *pngDir
= [NSHomeDirectory()stringByAppendingPathComponent:@"Documents"];
NSFileManager *fileMgr = [NSFileManagerdefaultManager];
NSString *FileDir = [NSStringstringWithFormat:@"%@/AnnexFiles",
pngDir];
NSError *err;
[fileMgr createDirectoryAtPath:FileDirwithIntermediateDirectories:YES attributes:nil error:&err];
NSString *FileFullPath = [FileDir stringByAppendingPathComponent:[DBTopicAnnexData Name]];
BOOL bRet = [fileMgrfileExistsAtPath:FileFullPath];
if (bRet) {
//
NSError *err;
[fileMgr removeItemAtPath:FileFullPath error:&err];
}
或者
// 清除本地配置数据
NSArray *paths
= NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSFileManager *fileMgr = [NSFileManager defaultManager];
NSString *MapLayerDataPath = [documentsDirectory stringByAppendingPathComponent:@"DBMapLayerData.xml"];
BOOL bRet = [fileMgrfileExistsAtPath:MapLayerDataPath];
if (bRet) {
//
NSError *err;
[fileMgr removeItemAtPath:MapLayerDataPatherror:&err];
}
NSString *pngDir
= [NSHomeDirectory()stringByAppendingPathComponent:@"Documents"];
NSFileManager *fileMgr = [NSFileManagerdefaultManager];
NSString *FileDir = [NSStringstringWithFormat:@"%@/AnnexFiles",
pngDir];
NSError *err;
[fileMgr createDirectoryAtPath:FileDirwithIntermediateDirectories:YES attributes:nil error:&err];
NSString *FileFullPath = [FileDir stringByAppendingPathComponent:[DBTopicAnnexData Name]];
BOOL bRet = [fileMgrfileExistsAtPath:FileFullPath];
if (bRet) {
//
NSError *err;
[fileMgr removeItemAtPath:FileFullPath error:&err];
}
或者
// 清除本地配置数据
NSArray *paths
= NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSFileManager *fileMgr = [NSFileManager defaultManager];
NSString *MapLayerDataPath = [documentsDirectory stringByAppendingPathComponent:@"DBMapLayerData.xml"];
BOOL bRet = [fileMgrfileExistsAtPath:MapLayerDataPath];
if (bRet) {
//
NSError *err;
[fileMgr removeItemAtPath:MapLayerDataPatherror:&err];
}