创建沙盒的路径:
NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *documentPaths= NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,
YES);
NSLog(@"documentPath %@",documentPaths);
NSString *ourDocumentPath=[documentPaths objectAtIndex:0];
NSLog(@"ourDocumentPath= %@",ourDocumentPath);
NSString *fileName=[ourDocumentPath stringByAppendingPathComponent:@"MOVeee"];
[fileManager createDirectoryAtPath:fileName withIntermediateDirectories:YES attributes:nil
error:nil];
添加文件夹,添加文件
NSString *testPath = [testDirectory stringByAppendingPathComponent:@"test00.txt"];
NSString *testPath2 = [testDirectory stringByAppendingPathComponent:@"test22.txt"];
NSString *testPath3 = [testDirectory stringByAppendingPathComponent:@"test33.txt"];
NSString *string = @"写入内容,write String";
[fileManager createFileAtPath:testPath contents:[string dataUsingEncoding:NSUTF8StringEncoding] attributes:nil];
[fileManager createFileAtPath:testPath2 contents:[string dataUsingEncoding:NSUTF8StringEncoding] attributes:nil];
[fileManager createFileAtPath:testPath3 contents:[string dataUsingEncoding:NSUTF8StringEncoding] attributes:nil];
获取目录列里所有文件名
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSLog(@"documentsDirectory%@",documentsDirectory);
NSFileManager *fileManage = [NSFileManager defaultManager];
NSString *myDirectory = [documentsDirectory stringByAppendingPathComponent:@"test"];
NSArray *file = [fileManage subpathsOfDirectoryAtPath: myDirectory error:nil];
NSLog(@"%@",file);
NSArray *files = [fileManage subpathsAtPath: myDirectory ];
NSLog(@"%@",files);
原文:http://blog.csdn.net/yangchen9931/article/details/44901749