·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> app软件开发 >> IOS开发 >> NSFileManager沙盒文件管理

NSFileManager沙盒文件管理

作者:佚名      IOS开发编辑:admin      更新时间:2022-07-23

文件夹创建,复制,移动,删除,检查是否存在,代码如下:

1.获取沙盒 document 路径,作为文件夹路径的基路径.

  NSString *document = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];

2.创建 NSFileMAnager:

  NSFileManager *manager = [NSFileManager defaultManager];

3.创建文件夹

  a.拼接文件夹路径: NSString *newFile = [document stringByAppendingPathComponent :@"QQQQ"];

  b.创建文件夹: [manager createDirectoryAtPath:newFile withIntermediateDirectories:YES attributes:nil error:nil];  

4.移动文件夹:

  a.拼接要移动到的地址: NSString *movePath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"QQQQ"];

  b.移动文件夹:[manager moveItemAtPath:newFile toPath:movePath error:nil];

5.判断文件夹是否存在

  [manager fileExistsAtPath:movePath]; 返回值 BOOL

6.删除文件夹

  [manager removeItemAtPath:movePath error:nil];

7.复制文件夹

  [manager copyItemAtPath:movePath toPath:newFile error:nil];