首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >文件名?路径名?基本名字?路径段命名标准

文件名?路径名?基本名字?路径段命名标准
EN

Stack Overflow用户
提问于 2018-03-23 02:11:36
回答 2查看 0关注 0票数 0

当我操作路径和文件名时,我总是陷入困境,因为我没有一个通用的命名系统。

我需要拿出一个命名标准,并坚持它,我想要清楚和一致的其他人,所以我是开放的学习规范的答案。

考虑一下这个玩具问题:(Windows示例,但希望答案应该是独立于平台的)

已经获得了文件夹的全名:C:\USERS\OddThinking\Documents\MySource。希望遍历下面的文件夹,并将所有.src编译到.obj。

在某个时候,将看到以下字符串。

代码语言:txt
复制
C:\users\OddThinking\Documents\My Source\Widget\foo.src

那么,将为这些部件使用什么标识符名称?

代码语言:txt
复制
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特有的术语吗?

EN

回答 2

Stack Overflow用户

发布于 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

完全/绝对路径

票数 0
EN

Stack Overflow用户

发布于 2018-03-23 11:49:42

当我不得不在Utilityclass中创建一系列函数时,这件事让我很困扰。GetFileName?还是GetFullName?GetApplicationPath意味着完整路径或目录名?我来自.NET背景,所以我认为我可以通过@BINRY来为其他优秀的答案添加更多的内容。

摘要:

  1. 路径:PATH指定文件系统中的唯一位置(除非其相对路径)。路径名称使用较少,但我会坚持使用路径-它几乎解释了它是什么。PATH可以指向文件或文件夹,甚至什么也不能指向(C:)。路径可以是:
代码语言:txt
复制
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命名路径是一致的。

  1. 根路径或根目录前者是.NET约定,后者在UNIX圈子中更常见。虽然我喜欢两者,但我更倾向于使用前者。与UNIX不同,Windows中有许多不同的根路径,每个分区都有一个。Unix系统有一个根目录,其中包含其他目录和文件的信息。例如。C:\是根路径。
  2. 文件夹文件夹名Widget,OddThinking等在你的情况下。这可能是Windows专用的约定(事实上,这是我自己奇怪的想法:),但我强烈反对盲人回答“目录”。但是对于普通用户目录来说,意味着作为一个文件夹(就像子文件夹、子目录),我认为从技术角度来看,“目录”听起来应该是目标的限定地址,而不是目标本身。
代码语言:txt
复制
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).

  1. 目录目录名前者一般用于实际生活,后者用于代码。这指的是完全限定的路径(或简单地全路径)直到目标父文件夹。在你的情况下,C:\users\OddThinking\Documents\My Source\Widget(是的,目录从来都不是指向文件的)。我在代码中使用目录名,因为目录是.NET中的一个类,目录名称是库本身所称的。
  2. 文件名、文件名和扩展名。就你而言:foo.src。文件名经常被MS使用,文件名可能意味着文件的basename或完整路径。所以我喜欢使用basename,这就是我在代码中所称的。在wiki上,也说文件名可能意味着完整的路径或者是basename。令人惊讶的是,即使在.NET中,我也可以找到basename的用法来表示文件的根名。
  3. 延拓文件名扩展名文件扩展名我喜欢最后一个。所有这些都是指同一件事,但又是一个争论的问题。
代码语言:txt
复制
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.

回答你:

  1. 关于你所给予的道路(A)不知道。不管怎样,我从来不需要一个人去。 (B)basename (C)我只是暂时称之为文件扩展名,我最不担心,因为我从来不需要在代码中单独命名它。 d)文件扩展名。 (E)我不认为这是一般目的的规定。不知道。在.NET基目录中,目录名与目录名称相同。 f)相对路径 (G)文件夹(父文件夹要命名为basename)foo.src) (H)目录名 (I)完整路径(甚至文件名)
  2. 总的来说(抱歉有点冗长,只是为了说明问题),但假设foo.src确实是一个文件(A)NA (B)basename (C)NA d)延期 (E)目录或简单路径 f)相对路径 g)NA (H)目录或简单路径 (I)完整路径(甚至文件名)

再举一个例子:

  1. 想想这条路C:\Documents and Settings\All Users\Application Data\s.sql...
代码语言:txt
复制
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.

  1. 现在想想这条路C:\Documents and Settings\All Users\Application Data
代码语言:txt
复制
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.

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100003216

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档