读写沙盒路径内容

来源:互联网 发布:成立子公司的好处知乎 编辑:程序博客网 时间:2024/06/05 17:55

//1.获取沙盒地址

    NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES)lastObject];

//2.将沙盒中的文件保存在数组中

self.urlArray = [selfgetAllFileNames:path];

//管理文件返回数组方法

- (NSArray *)getAllFileNames:(NSString *)dirPath{

    NSArray *files = [[NSFileManagerdefaultManager] subpathsOfDirectoryAtPath:dirPatherror:nil];

    return files;

}

//3.将array转换成可变数组(有利于展示在界面,方便增删)同步显示

self.mutableArray = [NSMutableArrayarrayWithArray:self.urlArray];

//查找文件名

BOOL blHave=[[NSFileManagerdefaultManager] fileExistsAtPath:@“自己的文件路径”];

//remove所要删除的文件地址

BOOL blDele= [fileManager removeItemAtPath:@“自己的文件路径”error:nil];

//如:在tableview上删除了数据源

[self.mutableArrayremoveObjectAtIndex:indexPath.row];

[tableView deleteRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationLeft];


原创粉丝点击