首先,好问题,我的+1。当我必须在Utility类中创建大量函数时,这件事让我很困扰。GetFileName吗?还是GetFullName ?GetApplicationPath是指完整路径还是目录名?等等。我来自。net背景,所以我认为我可以为@blinry的出色回答补充更多。
总结:(斜体字是我作为程序员不会使用的内容)
Path: Path specifies a unique location in the file system (unless its relative path). Path name is less often used, but I would stick with path - it pretty much explains what it is. Path can point to a file or a folder or even nothing (C:\). Path can be:
Relative Path: My Source\Widget\ is relative path as well as Widget\foo.src. Self explanatory.
Absolute Path or Full Path: Is the fully qualified path that points to the target. I tend to use the latter more often. C:\users\OddThinking\Documents\My Source\Widget\foo.src is hence full path. See at the end what I call full path that points to a file and that ends as a directory.
The wiki page and .NET naming for path is consistent.
Root Path or Root Directory: Former is .NET convention while latter is more heard in UNIX circles. Though I like both I tend to use the former more. In windows, unlike UNIX, has many different root paths, one for each partition. Unix systems have one root directory which holds information on other directories and files. Eg. C:\ is root path.
Folder or Folder Name: Widget, OddThinking etc in your case. This might be a Windows only convention (in fact its my own odd thinking :)), nevertheless I strongly object to blinry`s answer "Directory". Though for a normal user directory means the same as a folder (like subfolders, subdirectories), I believe from a technical angle "directory" should sound like a qualified address to the target and not the target itself. More below.
Sub Folders: With respect to users OddThinking and Documents are sub folders.
Sub Directories: With respect to users OddThinking\, OddThinking\Documents\ and OddThinking\Documents\My Source\Widget\ are sub directories. But we do not often need to bother about it, do we?
Child Folder: With respect to users OddThinking is a child folder (as well as sub folder)
Parent Folder: For OddThinking users is its parent folder (Just mentioning different terminologies, no big deal).
Directory or Directory Name: The former to use generally in real life, the latter to be in code. This refers to the fully qualified path (or simply full path) till the target's parent folder. In your case, C:\users\OddThinking\Documents\My Source\Widget (Yes a directory is never meant to point to a file). I use directory name in my code since directory is a class in .NET and Directory Name is what the library itself calls it. Its quite consistent with dirname used in UNIX systems.
File Name or Basename: Name of the file along with extension. In your case: foo.src. I would say that for a non technical use I prefer file name (it is what it means for an end user) but for technical purposes I would strictly stick with basename. File Name is often used by MS, but I am surprised how they are not consistent not just in documentation but even in library. There filename could mean either basename or full path of the file. So I favour basename, that's what I call them in code. This page on wiki too says file name could mean either full path or the basename. Surprisingly even in .NET I can find the usage basename to mean the root name of the file.
Extension or Filename Extension or File Extension: I like the last one. All refers to the same thing but what is it is again a matter of debate! Wiki says it is src while back then I remember reading that many of the languages interprets it as .src. Note the dot. So once again my take is, for casual uses it doesn't matter what it is, but as a programmer I always see extension as .src.
Ok I might have tried to fetch some standard usages, but here are two of my conventions I follow. And it is about full paths.
I generally call a full path that point to a file as file path. To me file path is clear cut, it tells me what it is. Though with file name I find it as the name of the file, in my code I call it file name. It's also consistent with "directory name". From the technical side, name refers to the fully qualified name! Frustratingly .NET uses the term file name (so I have my case here) and sometimes file path for this.
I call a full path that ends as a directory a directory. In fact one can call any piece of address that doesn't point to a file a directory. So C:\users\OddThinking\Documents\My Source\ is a directory, C:\users\OddThinking\ is a directory, or even OddThinking\Documents\My Source\ (better to call it sub directory or even better relative path - all that depends on the context you are dealing with it). Well above I mentioned something different about directory which is directory name. Here is my take on it: I'll get a new path to avoid confusion. What is this D:\Fruit\Apple\Pip\? A directory. But if the question is what is the directory or even better directory name of D:\Fruit\Apple\Pip\, the answer is D:\Fruit\Apple\. Hope its clear.
I would say it's better not to worry about the final two terms as that is what create the most confusion (for me personally). Just use the term full path!
回答你:
with respect to the path you have given
A) No idea. Anyways I never needed to get that one alone.
B) basename
C) I would just call it file extension for time being, I am least worried since I never needed that alone to be named in my code.
D) file extension surely.
E) I do not think this is a general purpose requirement. No idea. In .NET base directory is the same as directory name.
F) relative path
G) folder (parent folder to basename foo.src)
H) directory name
I) full path (or even file name)
in general (sorry for being a bit verbose, just to drive the point home) but assuming foo.src is indeed a file
A) NA
B) basename
C) NA
D) extension
E) directory or simply path
F) relative path
G) NA
H) directory or simply path
I) full path (or even file name)
举一个我的例子:
考虑路径C:\Documents and Settings\All Users\Application Data\s.sql。
C:\Documents and Settings\All用户\应用程序数据。SQL是完整路径(是一个文件名)
C:\Documents and Settings\All Users\Application Data\是目录名。
现在考虑路径C:\Documents and Settings\All Users\Application Data
C:\Documents and Settings\All Users\Application Data是完整路径(恰好是一个目录)
“C:\Documents and Settings\All Users”为目录名。
我的两点建议:
I follow this rule of thumb that when it comes to addressing a full address irrespective of its type, I almost always call it "full path". This not only eliminates the use of two terminologies for file path and folder path, it also avoids the potential confusion if you are going to name that of file as file name (which for most users right away translates to basename). But yes if you have to be specific about the type of path, its better to name then file name or directory instead of more generic "path".
Whatever it is you would have your own idea in mind, be consistent with it throughout. Have a consensus among team members that this means this and not that.
现在我有了一些练习。在OS X和android机器上使用的术语将会是一个新的品牌。所有这些都是关于文件系统中的物理路径。就网址而言,一套全新的术语将会出现。我希望有人能在同一条线索中填补空白:)我很高兴听到你所进行的公约。