iOS NSFileManager对沙盒文件及目录添加删除操作
2023-09-11 14:15:06 时间
iOS 使用 NSFileManager对沙盒里面的文件和目录,增加,修改,删除操作;
- (void)viewDidLoad { [super viewDidLoad]; self.title = @"NSFileManager"; NSFileManager *defauleManager = [NSFileManager defaultManager]; NSString *tempPath = NSTemporaryDirectory(); NSLog(@"%@",tempPath); NSString *thePath = nil; //创建一个目录: 在temp下创建 MyFoler目录 // thePath = [NSString stringWithFormat:@"%@/MyFolder",tempPath]; // [defauleManager createDirectoryAtPath:thePath withIntermediateDirectories:YES attributes:nil error:nil]; //写入一个文件 在 temp目录下 // NSString *aStr = @"hello world"; // thePath = [NSString stringWithFormat:@"%@hello.txt",tempPath]; // [aStr writeToFile:thePath atomically:YES encoding:NSUTF8StringEncoding error:nil]; //显示目录内容 //NSLog(@"temp目录内容:%@",[defauleManager contentsOfDirectoryAtPath:tempPath error:nil]); //删除一个文件 // NSString *deleteStr = @"delete Str"; // thePath = [NSString stringWithFormat:@"%@delete.txt",tempPath]; // [deleteStr writeToFile:thePath atomically:YES encoding:NSUTF8StringEncoding error:nil]; // NSLog(@"temp目录内容:删除之前:%@",[defauleManager contentsOfDirectoryAtPath:tempPath error:nil]); // [defauleManager removeItemAtPath:thePath error:nil]; // NSLog(@"temp目录内容:删除之后:%@",[defauleManager contentsOfDirectoryAtPath:tempPath error:nil]); //删除一个目录: // thePath = [NSString stringWithFormat:@"%@/TestFoler",tempPath]; // [defauleManager createDirectoryAtPath:thePath withIntermediateDirectories:YES attributes:nil error:nil]; // NSLog(@"temp目录内容:%@",[defauleManager contentsOfDirectoryAtPath:tempPath error:nil]); // [defauleManager removeItemAtPath:thePath error:nil]; // NSLog(@"temp目录内容:%@",[defauleManager contentsOfDirectoryAtPath:tempPath error:nil]); //获取目录下的所有文件列表: NSArray *fileList = [defauleManager contentsOfDirectoryAtPath:tempPath error:nil]; NSLog(@"%@",fileList); //判断一个目录是否是文件夹 //- (BOOL)fileExistsAtPath:(NSString *)path isDirectory:(BOOL *)isDirectory }
相关文章
- (NO.00005)iOS实现炸弹人游戏(十):游戏主角(三)
- iOS工程中的info.plist文件的完整研究
- iOS开发-常用第三方开源框架介绍(你了解的ios只是冰山一角)
- iOS开发 -- 为本地文件添加自定义属性的工具类
- iOS开发之网络编程--4、NSURLSessionDataTask实现文件下载(离线断点续传下载) <进度值显示优化>
- iOS开发之网络编程--3、NSURLSessionDataTask实现文件下载(离线断点续传下载)
- iOS开发之网络编程--小文件下载
- 三步教你iOS导入.ttf字体文件
- iOS之多控制器管理--项目中的常见文件
- iOS之UI--指示器HUD的创建和设置
- IOS打开pdf文件
- ios swift Data sha256加密
- ios swift 读取项目里的文件 读取并解析本地json文件 codable
- iOS 百度地图:手动(pod)导入百度步骑行导航的时候,不断报出下面的错误
- iOS 加载(读取)本地的json文件
- iOS在swift项目的桥接文件中导入oc的Category(类别 类目 分类 拓展)
- cordova build ios时出现Cannot read property 'toLowerCase' of undefined
- Ios开发之 -- js和ios的交互
- iOS_21团购_发送请求【点评】数据
- IOS使用APNS推送Payload字节数限制导致推送不成功
- Android 11.0 Launcher3仿ios长按app图标实现抖动动画开始拖拽停止动画