4

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?

user2083364
  • 744
  • 1
  • 7
  • 20

3 Answers3

9

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");
Greg
  • 25,317
  • 6
  • 53
  • 62
0

The following will help you:

-[NSFileManager createDirectoryAtPath:withIntermediateDirectories:attributes:error:]
Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140
0

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

Valentin Rocher
  • 11,667
  • 45
  • 59