Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create Subfolder in NSDocumentDirectory

I just wanted to know if 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] stringByAppendingPathComponent:@"TestFolder"];  
NSString *filePath =[dirPath stringByAppendingPathComponent:@"testimage.jpg"];  
[imageData writeToFile:filePath atomically:YES];

Thanks in advance for your support!

like image 683
Sean Avatar asked Jan 19 '10 15:01

Sean


2 Answers

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.

like image 105
zoul Avatar answered Oct 23 '22 23:10

zoul


The createDirectoryAtPath:attributes: method has been deprecated.

Use createDirectoryAtPath:withIntermediateDirectories:attributes:error: instead.

like image 21
TALLBOY Avatar answered Oct 23 '22 23:10

TALLBOY