質問

For example if I want to write file.txt into /folder1/folder2/folder3/ and noone of folders exists.

Is it the only way to create them manually?

役に立ちましたか?

解決

Try that it should do the job:

    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");

他のヒント

The following will help you:

-[NSFileManager createDirectoryAtPath:withIntermediateDirectories:attributes:error:]

You can use createDirectoryAtPath:withIntermediateDirectories:attributes:error: with YES in the intermediate directories parameter to create all the folders you need in the path.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top