开发者

What is the correct term for referring to a path and filename?

开发者 https://www.devze.com 2022-12-15 20:32 出处:网络
I want to use the correct term to make my API as intuitive as possible, so when a parameter is expected to be a full path and filename (ex \"C:\\Users\\Max\\Documents\\MyDocument.txt\") what is the co

I want to use the correct term to make my API as intuitive as possible, so when a parameter is expected to be a full path and filename (ex "C:\Users\Max\Documents\MyDocument.txt") what is the correct term?

  • filename开发者_Go百科 - that would just be MyDocument.txt, right?
  • path - that would just be C:\Users\Max\Documents, right?

What should I use for the parameter name? Would "file" be the appropriate name?

I feel kind of dumb asking this, but I want to make sure it's right.


My suggestion would be "Absolute file path" for some path pointing to a file, where as i would use "Absolute directory path" for a path pointing to a directory

In case of relative paths the change should be obvious.

If nothing else, you can always make a section in your documentation where you describe the meaning of certain terms you use.


The correct term is "Fully Qualified Name" (sometimes "FQN").

The term you should use in your API is "QualifiedName" or "QualifiedFilename"

Wikipedia has an entry for "Fully qualified file name" and defines it as "a file on a computer whose exact name is completely specified such that it is unambiguous and cannot be mistaken for any other file on that system."


A term often overused for this is URI, though your example isn't really one of those. I think you'll be perfectly clear if you just use "filepath" or "pathname."

For example, Java's file object uses "pathname" as the parameter name for the constructor on their File object.


Usually path is the full C:\Users\Max\Documents\MyDocument.txt while the C:\Users\Max\Documents\ part is usually known as the base directory or just directory.

You'll see in a lot of example code people write: C:\path\to\the\document.txt


I'd go with fullPath like you said path would be C:\Users\Max\Documents but reading fullPath would suggest path + filename.


I don't think there is One True Answer, maybe some consensus, but that's all we can hope for. I usually try to follow the conventions of the library I'm using (e.g., Cocoa, Java, or PHP). If I've got nothing to go by, I'd say:

  • File: the abstract thing being referred to by a name: the file handle
  • Path: a string indicating the location of a file or directory, either absolute or relative: /Users/Max/Documents/FooBar, ../Sibling/Zardoz
  • Name: the name of the file or directory, without location: FooBar, Zardoz, Documents


One easier solution you may have considered already is telling the consumer of the API what is expected in the XML documentation, which will also appear in Visual Studio intellisense if your compile the assembly with documentation, and distribute the .xml file.

/// <summary>
/// Saves the provided file to disk.
/// </summary>
/// <param name="filePath">The full path, including the filename of the file.</param>
public void SaveFile(string filePath)
{

}
0

精彩评论

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