fileExistsAtPath always return false

Posted on 2011-04-20
Last Modified: 2013-11-25
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.
Question by:opsl63-2
    LVL 24

    Expert Comment

    I'd check how fileExistsAtPath: really works maybe it needs a certain kind of Path, maybe a complete path?

    LVL 5

    Accepted Solution

    try using pathForResource:ofType: on NSBundle as an alternative, fileExistsAtPath requires a full path and you should not hard code the install location.

    Author Closing Comment

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Create a default user profile for Mac OS X 10.7/10.8 Create a user account on OS X that will be a template for every other user of that computer. I usually call it “profile” and make it an administrator account for the time being. 1. Install a…
    A lot of new and distinct gadgets are making their appearance every other day. The latest gadget that has wooed the attention of all gadget lovers and non gadget lovers alike is the Smartwatch. This tiny gadget is capable of offering live access to …
    The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
    The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now