Tutorial :fileExistsAtPath: (NSFileManager)


Is this method supposed to take a path as its argument?

It looks like it takes a filename as a path:

For example, /home/file.txt is a file, while /home/ is a path. This method looks like it takes the former as an argument.


Your distinction of "path" vs. "file" is not one that is common in Unix. Whether the final element of a path is a file or not doesn't affect the fact that it is a path. "/home/file.txt" looks like an absolute file path (though it could in fact be a deceptively named directory). "/home/" is an absolute directory path. Both are paths. (So is "foo/bar" â€" would you call that a "file" or a "path" in your terminology? Without inspecting the object at that path, we can't know whether it names a directory or a file.) Apple is using the term in its normal sense.


Yes, it takes a string that is a path - see the documentation:

The path of a file or directory. If path begins with a tilde (~), it must first be expanded with stringByExpandingTildeInPath, or this method returns NO.

Note that /home/file.txt is a path, just like /home/. The former however is no directory, while the latter is.


If you're wanting to look for distinctions between files and folders, see -fileExistsAtPath:isDirectory:.


BOOL isDirectory;  if ([self fileExistsAtPath:@"/Users/me/Subfolder" isDirectory:&isDirectory] && isDirectory)  {      // Exists and is a directory. Isn't that neat?  }  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »