views:

671

answers:

1

hello, I just wanted to know is it's possible to create a subfolder in the NSDocumentDirectory and write data into that created folder, like:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);    
NSString *dirPath =[[paths objectAtIndex:0] stringAppendingPathComponent:@"TestFolder"];  
NSString *filePath =[dirPath stringAppendingPathComponent:@"test.jpg"];  
[imageData writeToFile:filePath atomically:YES];

thanks in advance for your support

+2  A: 

The writeToFile might fail because the directory does not exist. If it does fail, you could try the NSFileManager class that has a createDirectoryAtPath:attributes: method.

zoul
Thanks a lot, you're right, i had to create the TestFolder with the NSFileManager first. Now it works!
Sean