Creating a subfolder in NSDocumentDirectory

I just wanted to find out if it is possible to create a subfolder in NSDocumentDirectory and write data to this created folder, for example:

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!

+5
objective-c folder nsdocument
source share
2 answers

writeToFile may fail because the directory does not exist. If this fails, you can try the NSFileManager class, which has the createDirectoryAtPath: attributes: method.

+5
source share
+5
source share

All Articles