Thursday, May 20, 2010

How to check if a file exists in Documents folder?

NSString *filePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"dirname/file.name"];

//check if file exists
NSFileManager *fm = [NSFileManager defaultManager];
BOOL success = [fm fileExistsAtPath:filePath];

Another Way

NSString* documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString* foofile = [documentsPath stringByAppendingPathComponent:@"foo.html"];
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:foofile];

No comments:

Post a Comment