fileExistsAtPath:
Returns a Boolean value that indicates whether a file or directory exists at a specified path.
- (BOOL)fileExistsAtPath:(NSString *)path
Parameters
- path
- The path of the file or directory. If path begins with a tilde (
~
), it must first be expanded withstringByExpandingTildeInPath
, otherwise, this method returnsNO
.
Return Value of [NSFileManager fileExistsAtPath]
YES
if a file at the specified path exists or NO
if the file does not exist or its existence could not be determined.Discussion of [NSFileManager fileExistsAtPath]
If the file at path is inaccessible to your app, perhaps because one or more parent directories are inaccessible, this method returns
NO
. If the final element in pathspecifies a symbolic link, this method traverses the link and returns YES
or NO
based on the existence of the file at the link destination.
Example of [NSFileManager fileExistsAtPath]
NSFileManager *myManager = [NSFileManager defaultManager];
NSString *documentsDirectory = NSHomeDirectory();
if([myManager fileExistsAtPath:[documentsDirectory stringByAppendingPathComponent:@"Music/songlist.txt"]]){
NSLog(@"file is there");
}