0

I want to create a sub folder to store the images which is captured by camera & also require to store images in to the database and retrieve the images From the database.

So please provide me help regarding how to create a folder in iPhone & how to store the images in to the database & retrieve them

EmptyStack
  • 51,274
  • 23
  • 147
  • 178
jaydev
  • 47
  • 8

1 Answers1

7

To create a directory in the documents folder,

- (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];
}
EmptyStack
  • 51,274
  • 23
  • 147
  • 178
  • @jaydev you ought to accept the answers that have helped you. To do that click on the checkbox next to the answer – Sathyajith Bhat Aug 10 '11 at 16:42
  • @EmptyStack Can you guide me how to retrieve data from these particular folders created. –  Oct 31 '12 at 07:15
  • Try this answer. http://stackoverflow.com/questions/6546563/read-a-txt-file-inside-documents-directory. In that change the line *NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"txtFile.txt"];* to *NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"yourDir/txtFile.txt"];* – EmptyStack Oct 31 '12 at 10:40