在iPhone中创建目录

时间:2011-04-16 10:18:44

标签: iphone objective-c ios ios4

我想创建一个子文件夹来存储由相机和相机拍摄的图像。还需要将图像存储到数据库中并从数据库中检索图像。

因此,请向我提供有关如何在iPhone和iPhone中创建文件夹的帮助。如何将图像存储到数据库和检索它们

1 个答案:

答案 0 :(得分:7)

文档文件夹中创建目录

- (void)createDirectoryInDocumentsFolderWithName:(NSString *)dirName {

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *yourDirPath = [documentsDirectory stringByAppendingPathComponent:dirName];     
    NSFileManager *fileManager = [NSFileManager defaultManager];
    BOOL isDir = YES;
    BOOL isDirExists = [fileManager fileExistsAtPath:yourDirPath isDirectory:&isDir];
    if (!isDirExists) [fileManager createDirectoryAtPath:yourDirPath withIntermediateDirectories:YES attributes:nil error:nil];
}