//创建文件管理对象
NSFileManager *fm = [NSFileManager defaultManager];
//1、获取文件的信息
NSString *filePath = @"/Users/apple/Desktop/arr.plist";
//我要获取 文件的信息(大小、创建时间、修改时间、权限.....)
NSError *err;
//获取文件的属性 attributesOfItemAtPath
NSDictionary *fileAttr = [fm attributesOfItemAtPath:filePath error:&err];
NSLog(@"fileAttr = %@",fileAttr);
// 2、获取目录子路径
//subpathsAtPath 获取当前目录及所有子目录下文件路径
filePath = @"/Users/apple/Desktop/test";
// NSArray *paths = [fm subpathsAtPath:filePath];
// NSLog(@"paths.count = %ld",paths.count);
//subpathsOfDirectoryAtPath 获取当前目录及所有子目录下文件路径
// NSArray *paths =[fm subpathsOfDirectoryAtPath:filePath error:&err];
// NSLog(@"path = %@",paths);
// 3、获取当前文件夹下地目录(不包括子目录)
NSArray *paths =[fm contentsOfDirectoryAtPath:filePath error:&err];
NSLog(@"path = %@",paths);
//创建文件管理对象
NSFileManager *fm = [NSFileManager defaultManager];
NSString *filePath = @"/Users/apple/Desktop/itcast/aaa/bbb";
//创建目录
// [fm createDirectoryAtPath:路径 withIntermediateDirectories:YES/NO --- YES表示创建子文件夹 attributes:属性的字典 error:错误信息]
NSError *err = nil;
//创建目录
// [fm createDirectoryAtPath:filePath withIntermediateDirectories:YES attributes:nil error:&err];
//
//
// if (err==nil) {
// NSLog(@"创建成功");
// }else{
//
// NSLog(@"err = %@",err);
// }
//复制文件
// itcast/aaa/bbb/1.txt
NSString *oldFilePath = @"/Users/apple/Desktop/itcast/aaa/bbb/1.txt";
// itcast/aaa/1.txt
NSString *goalFilePath =@"/Users/apple/Desktop/itcast/aaa/1.txt";
// //复制文件
// [fm copyItemAtPath:oldFilePath toPath:goalFilePath error:&err];
//
// if (err==nil) {
// NSLog(@"复制成功");
// }else{
//
// NSLog(@"err = %@",err);
// }
//移动文件(剪切)
// [fm moveItemAtPath:oldFilePath toPath:goalFilePath error:&err];
//
// if (err==nil) {
// NSLog(@"移动成功");
// }else{
//
// NSLog(@"err = %@",err);
// }
//删除文件
// [fm removeItemAtPath:goalFilePath error:&err];
// if (err==nil) {
// NSLog(@"删除成功");
// }else{
//
// NSLog(@"err = %@",err);
// }
//创建文件
NSString *str = @"见于不见,丈母娘就在那里,不躲不闪";
//NSData 文件操作
//输入输出流
NSData *data = [str dataUsingEncoding:NSUTF8StringEncoding];
//创建文件
if([fm createFileAtPath:goalFilePath contents:data attributes:nil]){
NSLog(@"文件创建成功");
}
//删除目录
oldFilePath = @"/Users/apple/Desktop/itcast/aaa/";
[fm removeItemAtPath:oldFilePath error:&err];