0

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?

4

2 回答 2

3

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) {}
于 2012-06-20T18:11:08.110 回答
1

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)
...
于 2012-06-20T18:07:45.910 回答