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.
opsl63-2Asked:
Who is Participating?
 
mad_macCommented:
try using pathForResource:ofType: on NSBundle as an alternative, fileExistsAtPath requires a full path and you should not hard code the install location.
0
 
fridomCEO/ProgrammerCommented:
I'd check how fileExistsAtPath: really works maybe it needs a certain kind of Path, maybe a complete path?

0
 
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.