title: Deleting/Overwriting Image files on iphone obj c
body: <p>I am attempting to delete or overwrite an image within a specific directory. I grab all my images in an array and place in a table view. When an image is clicked photo roll is opened and the user chooses an image. when the imagepicker controller is being released I call out my methods to try and delete the original image and save the new image to the specific filepath.  I receive a odd error when deleting the image and not sure how I can give a better log to save the image but it is not saving either. I would appreciate an input! </p>
  
  <pre><code>    - (void)imagePickerController:(UIImagePickerController *)picker   
  didFinishPickingMediaWithInfo:(NSDictionary *)info {
  NSLog(@"image picker did finish");
  
  
  
  
  widgetImg.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
  
  change.enabled = YES;
  
  [self saveImage:widgetImg.image :ImgName];
  NSString *path = [NSString 
  stringWithFormat:@"/Library/Themes/%@/iSetUp/UserPhotos/%@",selectedThemeName,ImgName]; 
  
  
  NSFileManager *fileManager = [NSFileManager defaultManager];
  NSError *error;
  BOOL fileExists = [fileManager fileExistsAtPath:path];
  NSLog(@"Path to file: %@", path);        
  NSLog(@"File exists: %d", fileExists);
  NSLog(@"Is deletable file at path: %d", [fileManager isDeletableFileAtPath:path]);
  if (fileExists) 
  {
      BOOL success = [fileManager removeItemAtPath:path error:&amp;error];
      if (!success) NSLog(@"Error: %@", [error localizedDescription]);
  }
  
  
  [self dismissModalViewControllerAnimated:YES]; 
  
  
  
  }
  
  
  
  - (void)saveImage:(UIImage*)image:(NSString*)imageName {  
  //convert image into .png format.  
  NSData *imageData = UIImagePNGRepresentation(image);  
  NSFileManager *fileManager = [NSFileManager defaultManager];   
  NSString *IMGPath = [NSString 
  stringWithFormat:@"/Library/Themes/%@/iSetUp/UserPhotos/",selectedThemeName]; 
  
  
  [fileManager createFileAtPath:IMGPath contents:imageData attributes:nil];  
  NSLog(@"image saved"); 
  
  } 
  
  
  2012-03-29 16:05:05.907 iSetUp[1258:707] image picker did finish
  2012-03-29 16:05:09.046 iSetUp[1258:707] image saved
  2012-03-29 16:05:09.047 iSetUp[1258:707] Path to file:   
  /Library/Themes/Modernistic/iSetUp/UserPhotos/IMG_0183.JPG
  2012-03-29 16:05:09.048 iSetUp[1258:707] File exists: 1
  2012-03-29 16:05:09.049 iSetUp[1258:707] Is deletable file at path: 0
  2012-03-29 16:05:09.053 iSetUp[1258:707] Error: The operation couldn’t be completed.   
  (Cocoa error 513.)
  </code></pre>