开发者

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 for开发者_JAVA技巧mer 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:

Parameters
path
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:.

Usage:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜