Create a folder inside documents folder in iOS apps

Mina Mikhael picture Mina Mikhael · Nov 19, 2009 · Viewed 108.4k times · Source

I just want to create new folders in the documents folder of my iPhone app.

Does anybody know how to do that?

Appreciate your help!

Answer

Vladimir picture Vladimir · Nov 19, 2009

I do that the following way:

NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder
NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"/MyFolder"];

if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath])
    [[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:&error]; //Create folder