iOS NSFileManager对沙盒文件及目录添加删除操作
2013-12-18 10:27
471 查看
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 }
相关文章推荐
- iOS 沙盒目录结构和文件操作(NSFileManager)(一)
- iOS 沙盒目录结构和文件操作(NSFileManager)(二)
- ios文件操作之目录操作-NSFileManager
- iOS 沙盒目录结构和文件操作(NSFileHandle)(三)
- iOS沙盒机制及文件操作 NSFileManager的基本使用
- Objective-C文件和目录操作,IOS文件操作,NSFileManager使用文件操作
- iOS文件和目录操作,iOS文件操作,NSFileManager使用文件操作:
- iOS——文件操作NSFileManager (创建、删除,复制,粘贴)
- IOS开发 沙盒中的文件操作和文件系统NSFilemanager的操作
- Objective-C文件和目录操作,IOS文件操作,NSFileManager使用文件操作
- IOS(sandbox)沙盒和文件操作(NSFileManager)
- [绍棠] iOS文件目录和文件操作 及NSFileManager的读写操作
- Objective-C文件和目录操作,IOS文件操作,NSFileManager使用文件操作
- iOS学习之iOS沙盒(sandbox)机制和文件操作(三)——NSFileManager
- iOS 沙盒路径操作:新建/删除文件和文件夹
- ios学习笔记:文件操作(NSFileManager)iOS的沙盒中
- Objective-C文件和目录操作,IOS文件操作,NSFileManager使用文件操作
- iOS文件系统---沙盒(sandbox),NSFileManager,NSFileHandle, NSData, 目录,文件
- Objective-C文件和目录操作,IOS文件操作,NSFileManager使用文件操作
- php目录、文件 遍历 删除 创建 操作 (php教程四)