当我操作路径和文件名时,我总是陷入困境,因为我没有一个通用的命名系统。
我需要拿出一个命名标准,并坚持它,我想要清楚和一致的其他人,所以我是开放的学习规范的答案。
考虑一下这个玩具问题:(Windows示例,但希望答案应该是独立于平台的)
已经获得了文件夹的全名:C:\USERS\OddThinking\Documents\MySource。希望遍历下面的文件夹,并将所有.src编译到.obj。
在某个时候,将看到以下字符串。
C:\users\OddThinking\Documents\My Source\Widget\foo.src
那么,将为这些部件使用什么标识符名称?
A) foo
B) foo.src
C) src
D) .src
E) C:\users\OddThinking\Documents\My Source\ - i.e. the top of the tree.
F) Widget\foo.src - i.e. the path from the top of the tree to the leaf.
G) Widget - i.e. one node of the tree.
H) C:\users\OddThinking\Documents\My Source\Widget\ - i.e. the name of the folder
I) C:\users\OddThinking\Documents\My Source\Widget\foo.src
让我给你一些答案,让你开始。
(A)基本名称?
(B)档案名称?还是文件名?在选择标识符名称时,区别是很重要的,而且我在这里从来不一致。
(C)延期
d)延期。这就是我所说的C。我应该避免存储点,然后在需要的时候放进去吗?如果特定文件上没有点怎么办?
h)路径名称?还是等一下,这只是一条路?
(I)文件名。等等,这就是我所说的C.PATH。等等,这就是我所称的H.也许H应该是文件夹的名字。不过,“文件夹”不是Windows特有的术语吗?
发布于 2018-03-23 10:46:24
我认为你对“标准”命名规则的追求是徒劳的。以下是我根据现有的知名项目提出的建议:
(A)C:\User\Oddking\Document\MySource\Widget**Foo**.src
维姆称之为文件根(帮助文件名-修饰符)
(B)C:\User\Oddking\Document\MySource\Widget**foo.src**
文件名或基名
C)C:\user\OddThinking\Documents\MySource\Widget\foo.SRC(无点)
文件/扩展名
(D)C:\user\Oddking\Document\MySource\Widget\foo.src(带圆点)
也文件扩展名。只需在没有点的情况下存储,如果文件上没有点,它就没有扩展名。
(E)C:\User\Oddking\Document\MySource**Widget\foo.src
树顶
没有约定,吉特称之为基目录
(F)C:\User\Oddking\Document\My Source**Widget\foo.src**
从树顶到叶子的路径
相对路径
(G)C:\User\Oddking\Document\My Source**Widget**\fo.src
树的一个节点
没有约定,也许是个简单的目录
(H)C:\User\Oddking\Documents\MySource\Widget**f.src
dir名称
(I)C:\User\OddThinking\Documents\MySource\Widget\foo.src
完全/绝对路径
发布于 2018-03-23 11:49:42
当我不得不在Utilityclass中创建一系列函数时,这件事让我很困扰。GetFileName?还是GetFullName?GetApplicationPath意味着完整路径或目录名?我来自.NET背景,所以我认为我可以通过@BINRY来为其他优秀的答案添加更多的内容。
摘要:
1. **Relative Path**: `My Source\Widget\` is relative path as well as `Widget\foo.src`. Self explanatory.
2. **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.
WIKI页面和.NET命名路径是一致的。
C:\
是根路径。Widget,OddThinking
等在你的情况下。这可能是Windows专用的约定(事实上,这是我自己奇怪的想法:),但我强烈反对盲人回答“目录”。但是对于普通用户目录来说,意味着作为一个文件夹(就像子文件夹、子目录),我认为从技术角度来看,“目录”听起来应该是目标的限定地址,而不是目标本身。1. **Sub Folders**: With respect to `users` `OddThinking` and `Documents` are sub folders.
2. **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?
3. **Child Folder**: With respect to `users` `OddThinking` is a child folder (as well as sub folder)
4. **Parent Folder**: For `OddThinking` `users` is its parent folder (Just mentioning different terminologies, no big deal).
C:\users\OddThinking\Documents\My Source\Widget
(是的,目录从来都不是指向文件的)。我在代码中使用目录名,因为目录是.NET中的一个类,目录名称是库本身所称的。foo.src
。文件名经常被MS使用,文件名可能意味着文件的basename或完整路径。所以我喜欢使用basename,这就是我在代码中所称的。在wiki上,也说文件名可能意味着完整的路径或者是basename。令人惊讶的是,即使在.NET中,我也可以找到basename的用法来表示文件的根名。1. 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.
2. 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.
回答你:
foo.src
)
(H)目录名
(I)完整路径(甚至文件名)foo.src
确实是一个文件(A)NA
(B)basename
(C)NA
d)延期
(E)目录或简单路径
f)相对路径
g)NA
(H)目录或简单路径
(I)完整路径(甚至文件名)再举一个例子:
C:\Documents and Settings\All Users\Application Data\s.sql
...1. `C:\Documents and Settings\All Users\Application Data\s.sql` is the full path (which is a file name)
2. `C:\Documents and Settings\All Users\Application Data\` is the directory name.
C:\Documents and Settings\All Users\Application Data
1. `C:\Documents and Settings\All Users\Application Data` is the full path (which happens to be a directory)
2. `C:\Documents and Settings\All Users` is the directory name.
https://stackoverflow.com/questions/-100003216
复制相似问题