views:

146

answers:

3

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.

A: 

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.

Georg Fritzsche
It looks like it takes a filename not a path
awakeFromNib
Why would you think it does? The parameter is even named `path`.
Georg Fritzsche
The parameter is named path but the code that I'm looking at is passing a file name.
awakeFromNib
I thought that a path the directory where the file resides.
awakeFromNib
No, paths can identify both files and directories, see e.g. [Wikipedia](http://en.wikipedia.org/wiki/Path_%28computing%29): *"A path, the general form of a filename or of a directory name, specifies a unique location in a file system."*
Georg Fritzsche
awakeFromNib: A filename is just that: A name of a file. It also functions as a relative pathname. A pathname can be absolute or relative; a relative pathname is relative to the current working directory, while an absolute pathname is just that: A complete pathname of something in the file-system. Note that a relative pathname can consist of only a single component (a name) and an absolute pathname can consist of no components at all (just /, the root directory), and any pathname can refer to a file, directory, something else, or nothing at all.
Peter Hosey
+2  A: 

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.

Chuck
+1  A: 

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?
}
Joshua Nozzi