文件操作

来源:互联网 发布:用友软件销售技巧 编辑:程序博客网 时间:2024/06/10 07:38






显示Mac隐藏文件的命令:defaults write com.apple.finder AppleShowAllFiles -bool true
隐藏Mac隐藏文件的命令:defaults write com.apple.finder AppleShowAllFiles -bool false
输完单击Enter键,退出终端,重新启动Finder就可以了
重启Finder:鼠标单击窗口左上角的苹果标志-->强制退出-->Finder-->


复制代码
  1.         //NSCachesDirectory NSCachesDirectory NSLibraryDirectory 
  2.         NSString *homeDirectory = NSHomeDirectory(); //获取程序HOME目录
  3.         NSString *tempDirectory = NSTemporaryDirectory(); //获取程序缓存目录
  4.         NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSAllDomainsMask, YES); //获取document目录
  5.         NSString *documentPath = [documentPaths objectAtIndex:0];
  6.         NSArray *cachesPaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSAllDomainsMask, YES); //获取cache目录
  7.         NSString *cachePath = [cachesPaths objectAtIndex:0];
  8.         NSArray *libraryPaths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSAllDomainsMask, YES); //所有library目录
  9.         NSString *libraryPath = [libraryPaths objectAtIndex:0];
  10.         NSString *filePath = [docDir stringByAppendingPathComponent:@"testFile.txt"];
  11.         [array writeToFile:filePath atomically:YES]; //写入文件
  12.         NSArray *arr = [[NSArray alloc] initWithContentsOfFile: filePath] 读取文件Path];
  13.         NSFileManager *fileManager = [NSFileManager defaultManager];
  14.         NSString *testDirectory = [documentsDirectory stringByAppendingPathComponent:@"test"];         //创建目录        [fileManager createDirectoryAtPath:testDirectory withIntermediateDirectories:YES attributes:nil error:nil];
  15.         //创建文件
  16.         NSString *testPath4 = [testDirectory stringByAppendingPathComponent:@"TEST44.txt"];
  17.         NSString *string = @"写入内容,write String";
  18.         [fileManager createFileAtPath:testPath4 contents:[string dataUsingEncoding:NSUTF8StringEncoding] attributes:nil];
  19.         //遍历目录
  20.         NSArray *file = [fileManage subpathsAtPath:myDirectory];
  21.         NSArray *files = [fileManage subpathsOfDirectoryAtPath:myDirectory error:nil];
  22.         //更改到待操作的目录下
  23.         [fileManager changeCurrentDirectoryPath:[documentsDirectory stringByExpandingTildeInPath]];
  24.         //创建文件fileName文件名称,contents文件的内容,如果开始没有内容可以设置为nil,attributes文件的属性,初始为nil
  25.         NSString * fileName = @"testFileNSFileManager.txt";
  26.         NSData *data = [fileManager contentsAtPath:fileName];
  27.         [fileManager createFileAtPath:fileName contents:data attributes:nil];
  28.         [fileManager removeItemAtPath:fileName  error:nil];

0 0