Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective-C. Create file at path which doesn't exist?

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?

like image 807
user2083364 Avatar asked Jan 12 '23 18:01

user2083364


1 Answers

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");
like image 80
Greg Avatar answered Jan 24 '23 12:01

Greg