fileManager的基本应用:查看列表
NSFileManager *fileManager=[NSFileManager defaultManager]; NSArray *documentPaths=NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory,NSAllDomainsMask , YES); for (NSString *str in documentPaths) { NSLog(@"documentPaths:%@",str); } NSString *documentDir=[documentPaths objectAtIndex:0] ; NSLog(@"documentDir:%@",documentDir);
结果如下:
2013-06-14 16:30:48.253 helloword[1092:c07] documentPaths:/Users/qing/Library/Application Support/iPhone Simulator/6.1/Applications/A3EEDA4B-0F5E-49E5-91D8-FBCCD388B539/Library/Documentation 2013-06-14 16:30:48.258 helloword[1092:c07] documentPaths:/Library/Documentation 2013-06-14 16:30:48.258 helloword[1092:c07] documentPaths:/Network/Library/Documentation 2013-06-14 16:30:48.259 helloword[1092:c07] documentPaths:/System/Library/Documentation 2013-06-14 16:30:48.260 helloword[1092:c07] documentDir:/Users/qing/Library/Application Support/iPhone Simulator/6.1/Applications/A3EEDA4B-0F5E-49E5-91D8-FBCCD388B539/Library/Documentation
NSSearchPathForDirectoriesInDomains:
NSArray *documentPaths=NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory,NSUserDomainMask , YES); //documentPaths:/Users/qing/Library/Application Support/iPhone Simulator/6.1/Applications/A3EEDA4B-0F5E-49E5-91D8-FBCCD388B539/Library/Documentation documentPaths=NSSearchPathForDirectoriesInDomains(NSDownloadsDirectory,NSAllDomainsMask , YES); ///Users/qing/Library/Application Support/iPhone Simulator/6.1/Applications/A3EEDA4B-0F5E-49E5-91D8-FBCCD388B539/Downloads
相关推荐
AppFolder AppFolder是一个轻量级的框架,可让您设计应用程序容器内目录的友好,强类型表示。 所有系统目录(例如“ Caches /”和“ Application Support /”)都已经存在,您只需使用几行代码即可添加您的目录。...
// NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); // NSString * path = [paths objectAtIndex:0]; // path = [path stringByAppendingString:[NSString ...
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; // 获取Library目录 paths = ...
在iOS和macOS开发中,我们可以使用`FileManager`类和`NSSearchPathForDirectoriesInDomains`函数来获取沙盒路径。 - iOS Swift示例: ```swift let documentsURL = FileManager.default.urls(for: .document...
1、获取程序的Home目录 NSString *path = NSHomeDirectory(); NSLog(@"path:%@",path);... NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *
可以使用`NSSearchPathForDirectoriesInDomains`方法,传入`NSCachesDirectory`和`NSUserDomainMask`来获取。 ```objc NSArray *cachePaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, ...
通过`NSSearchPathForDirectoriesInDomains`方法,我们可以指定目录类型(如NSDocumentDirectory)和域(如NSUserDomainMask,代表用户域)来获取相应的路径。 源码示例"NSFileManager_DirectoryLocations"很可能...
通过NSSearchPathForDirectoriesInDomains获取当前应用的文档目录路径,然后构造出日志文件的完整路径。 实现代码如下: ```objective-c - (void)redirectConsoleLog { #ifdef DEBUG NSArray *paths = ...
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; // 设置当前工作目录为文档目录 [file...
NSString *docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]; NSString *path = [docPath stringByAppendingPathComponent:@"person.yangyang"]; ...
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *path = [paths lastObject]; path = [path stringByAppendingFormat:@"%@\aa", path]; NSLog...
NSString *filePath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject stringByAppendingPathComponent:@"audio.amr"]; // 初始化AVAudioPlayer NSError *error; ...
3. 获取Documents路径:使用NSSearchPathForDirectoriesInDomains()函数,并指定NSDocumentDirectory和NSUserDomainMask,可以定位到Documents目录。然后可以通过字符串操作添加自己的文件路径,比如添加一个名为...
NSString *filePath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; filePath = [filePath stringByAppendingPathComponent:@"data.plist"]; NSData *...
1. 文件路径:使用`NSSearchPathForDirectoriesInDomains`获取沙盒路径,例如`Documents`目录可以通过`NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)`获取。 2. 用户隐私:...
NSString *filePath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]; NSString *archivePath = [filePath stringByAppendingPathComponent:@"person.archive"];...
NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; NSLog(@"%@", path); // 指定要检查的文件路径 NSString *filePath = [path ...
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]; NSString *filePath = [documentsDirectory stringByAppendingPathComponent:...