例如,如果我想将file.txt写入/ folder1 / folder2 / folder3 /并且没有文件夹存在。
这是手动创建它们的唯一方法吗?
答案 0 :(得分:9)
尝试它应该做的工作:
NSString * yourPath = @"/folder1/folder2/folder3";
NSError * error = nil;
BOOL success = [[NSFileManager defaultManager] createDirectoryAtPath: yourPath
withIntermediateDirectories:YES
attributes:nil
error:&error];
if (!success)
NSLog(@"Error");
else
NSLog(@"Success");
答案 1 :(得分:0)
以下内容对您有所帮助:
-[NSFileManager createDirectoryAtPath:withIntermediateDirectories:attributes:error:]
答案 2 :(得分:0)
您可以在中间目录参数中使用createDirectoryAtPath:withIntermediateDirectories:attributes:error:
和YES来创建路径中所需的所有文件夹。