Create Subfolder in NSDocumentDirectory
Asked Answered
L

2

5

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!

Ludeman answered 19/1, 2010 at 15:2 Comment(0)
M
5

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.

Maeda answered 19/1, 2010 at 15:19 Comment(1)
Thanks a lot, you're right, i had to create the TestFolder with the NSFileManager first. Now it works!Ludeman
B
5

The createDirectoryAtPath:attributes: method has been deprecated.

Use createDirectoryAtPath:withIntermediateDirectories:attributes:error: instead.

Buran answered 1/2, 2011 at 18:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.