Home > Tutorials > Checking whether a file exists

Checking whether a file exists

April 28th, 2009

To check whether a file exists is very simple in Objective C, simply create an NSFileManager object, then feed the NSString of the file directory to the fileExistsAtPath method in the NSFileManager object.

NSString* myFileTxt = [[NSBundle mainBundle] pathForResource:@"myFile"
                                             ofType:@"txt"];
NSFileManager* fileManager = [NSFileManager defaultManager];
if(![fileManager fileExistsAtPath:myFileTxt])
{
// file doesn't exist
}
Author: admin Categories: Tutorials Tags:
  1. May 23rd, 2009 at 14:09 | #1

    I was just now googling around about this when I came by your post. I’m only dropping by to say that I truly enjoyed reading this post, it’s really well written. Are you planning toblog more on this? It seems like there is more fodder here for future posts.

  1. No trackbacks yet.