1。实现
- (BOOL)createDirectoryAtPath:(NSString *)path withIntermediateDirectories:(BOOL)createIntermediates attributes:(NSDictionary *)attributes error:(NSError **)error
createIntermediates:YES-若path中某一目录不存在,则创建它
NO-若path中某一目录不存在,则此方法返回NO,创建失败
例如:要创建文件夹.../tmp/data/images,其中,data文件夹不存在,若用YES,则此方法会连带创建data及data下的images;若NO,则创建失败
e.g.
NSFileManager *fileManager = [[NSFileManager alloc] init];
NSString *tempDir = NSTemporaryDirectory();
NSString *imagesDir = [tempDir stringByAppendingPathComponent:@"images"];
NSError *error = nil;
if ([fileManager createDirectoryAtPath:imagesDir withIntermediateDirectories:YES attributes:nil error:&error]){
NSLog(@"Successfully created the directory");
} else {
NSLog(@"Failed to create the directory. Error = %@", error);
}