views:

958

answers:

1

Hello,

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!

+4  A: 

I do that the following way:

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 attributes:nil]; //Create folder
Vladimir
thanks for the reply,it works but it creates the folder "MyFolder" beside the documents folder of the app .. not inside it.don't know why actually
zanque
Sorry - was a typo there - must append @"/MyFolder", not @"MyFolder" to a documents path.
Vladimir
yes, i discovered that, thanks for help :)
zanque
You might want to change the third line toNSString *dataPath = [documentsDirectory stringByAppendingString:@"/MyFolder"];since NSSearchPathForDirectoriesInDomains doesn't return trailing slashes.
Andreas
I fixed the code to use the more correct "stringByAppendingPathComponent", which does the right thing regardless of either input string having a "/" or not.
Kendall Helmstetter Gelner