title: How can I make a folder in NSDocument directory where I can save all the photos and delete the data from same folder when I want?
body: <p>I have a tableView where for each cell I'm getting an image url string and I'm saving all data in the NSDocument directory.</p>
  
  <p>I want to store all the data in folder made in the NSDocument directory and I also want to delete all the contents in that folder later. How to do it?</p>
  
  <p>this is the method I'm using </p>
  
  <pre><code>(void)setThumbnailTo :(UITableViewCell *)cell withRefString:(NSString *)string   {
  
  
     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
  
     NSString *documentsDirectory = [paths objectAtIndex:0]; 
  
  
     NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"patientPhotoFolder"];
  
  
     NSString *imgPath = [string stringByReplacingOccurrencesOfString:@"amp;" withString:@""];
  
     imgPath = [imgPath stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
  
     NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
  
     NSString *key = [self sha1:imgPath];
  
     NSString *fileToSave = [documentsPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.jpg",key]];
  
  
     BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:fileToSave];
     if (!fileExists)
     {
         dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0ul);
          dispatch_async(queue, ^{
              NSData *imageData=[NSData dataWithContentsOfURL:[NSURL URLWithString:imgPath]];
  
  
              UIImage *image = [[UIImage alloc] initWithData:imageData];
  
              NSData *jpegData = UIImageJPEGRepresentation(image,4);
  
              [[NSFileManager defaultManager] createFileAtPath:fileToSave contents:jpegData attributes:nil];
  
              dispatch_sync(dispatch_get_main_queue(), ^{
                 patientPhoto.image = image;
              });
          });
          patientPhoto.image = [UIImage imageNamed:@"patientPhoto.png"];
      }else{
          UIImage *image = [UIImage imageWithContentsOfFile:fileToSave];
          if(!image) image = [UIImage imageNamed:@"patientPhoto.png"];
          patientPhoto.image = image;
      }
  }
  </code></pre>