iOS 使用 NSFileManager对沙盒里面的文件和目录,增长,修改,删除操做;atom
- (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 }