显示Mac隐藏文件的命令:defaults write com.apple.finder AppleShowAllFiles -bool true
隐藏Mac隐藏文件的命令:defaults write com.apple.finder AppleShowAllFiles -bool false
输完单击Enter键,退出终端,重新启动Finder就可以了
重启Finder:鼠标单击窗口左上角的苹果标志-->强制退出-->Finder-->
复制代码
- //NSCachesDirectory NSCachesDirectory NSLibraryDirectory
- NSString *homeDirectory = NSHomeDirectory(); //获取程序HOME目录
- NSString *tempDirectory = NSTemporaryDirectory(); //获取程序缓存目录
- NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSAllDomainsMask, YES); //获取document目录
- NSString *documentPath = [documentPaths objectAtIndex:0];
- NSArray *cachesPaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSAllDomainsMask, YES); //获取cache目录
- NSString *cachePath = [cachesPaths objectAtIndex:0];
-
- NSArray *libraryPaths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSAllDomainsMask, YES); //所有library目录
- NSString *libraryPath = [libraryPaths objectAtIndex:0];
- NSString *filePath = [docDir stringByAppendingPathComponent:@"testFile.txt"];
- [array writeToFile:filePath atomically:YES]; //写入文件
- NSArray *arr = [[NSArray alloc] initWithContentsOfFile: filePath] 读取文件Path];
- NSFileManager *fileManager = [NSFileManager defaultManager];
- NSString *testDirectory = [documentsDirectory stringByAppendingPathComponent:@"test"]; //创建目录 [fileManager createDirectoryAtPath:testDirectory withIntermediateDirectories:YES attributes:nil error:nil];
- //创建文件
- NSString *testPath4 = [testDirectory stringByAppendingPathComponent:@"TEST44.txt"];
- NSString *string = @"写入内容,write String";
- [fileManager createFileAtPath:testPath4 contents:[string dataUsingEncoding:NSUTF8StringEncoding] attributes:nil];
- //遍历目录
- NSArray *file = [fileManage subpathsAtPath:myDirectory];
- NSArray *files = [fileManage subpathsOfDirectoryAtPath:myDirectory error:nil];
- //更改到待操作的目录下
- [fileManager changeCurrentDirectoryPath:[documentsDirectory stringByExpandingTildeInPath]];
- //创建文件fileName文件名称,contents文件的内容,如果开始没有内容可以设置为nil,attributes文件的属性,初始为nil
- NSString * fileName = @"testFileNSFileManager.txt";
- NSData *data = [fileManager contentsAtPath:fileName];
- [fileManager createFileAtPath:fileName contents:data attributes:nil];
- [fileManager removeItemAtPath:fileName error:nil];
-
-
|