The Man
The Man

Reputation: 1462

File Manager - File Not Found - Objective C

This is driving me crazy...

With this simple code I keep getting file not found on my ipad device...

NSFileManager *filemgr;
    
    filemgr = [NSFileManager defaultManager];
    
    if ([filemgr fileExistsAtPath: @"scoreCards.dgs" ] == YES)
        NSLog (@"File exists");
    else
        NSLog (@"File not found");

Xcode

Am I missing something?

Upvotes: 0

Views: 1023

Answers (2)

taskinoor
taskinoor

Reputation: 46037

You need to get the resource file path using pathForResource:ofType: method of NSBundle class.

NSString *path = [[NSBundle mainBundle] pathForResource:@"scoreCards" ofType:@"dgs"];
if ([filemgr fileExistsAtPath:path ] == YES) {}

Upvotes: 3

sergio
sergio

Reputation: 69027

Assuming that your file is bundled with the app, you could use:

NSFileManager *filemgr;
filemgr = [NSFileManager defaultManager];

NSString* filePath = [[NSBundle mainBundle] pathForResource:@"scoreCards" ofType:@"dgs"]
if ([filemgr fileExistsAtPath: filePath ] == YES)
...

Upvotes: 1

Related Questions