[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2091
  • Last Modified:

fileExistsAtPath always return false

I'm trying to check if an image exists using the fileExistsAtPath method of NSFileManager :

Product *prod = (Product *)[products objectAtIndex:i];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *pathForFile = prod.img_mini;
NSLog(@"PathForFile : %@", pathForFile);
if ([fileManager fileExistsAtPath:pathForFile]) 
  NSLog(@"File %@ exists !", prod.img_mini);

Open in new window

But this method always return false even if files exists in the project. Files are at the root of my project and placed in a groupe "ProductsImages". Do i have to mention this group somewhere ?

Thanks for your help.
1 Solution
I'd check how fileExistsAtPath: really works maybe it needs a certain kind of Path, maybe a complete path?

try using pathForResource:ofType: on NSBundle as an alternative, fileExistsAtPath requires a full path and you should not hard code the install location.
opsl63-2Author Commented:
Thanks, it works. But I had a complete filename in my database. So I had to split this filename to get the extension of the file and the filename without extension. Thank you again.

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now