go - path.Match 和 filepath.Match 有什么区别?

标签 go glob

两者的文档和代码看起来是一样的。 为什么有两个重复的函数?

https://golang.org/pkg/path/#Match

https://golang.org/pkg/path/filepath/#Match

最佳答案

它们不是“重复项”,它们是不同包的一部分,因此您应该在它们包的上下文中检查和解释它们。

包裹path “实现操作斜杠分隔路径的实用程序”独立于平台/操作系统。

包裹path/filepath “实现以与目标操作系统定义的文件路径兼容的方式操作文件名路径的实用程序

因此,例如 path/filepath 处理操作系统之间的路径分隔符差异。

如果您仔细查看 filepath.Match() 的文档, 它结束于:

On Windows, escaping is disabled. Instead, '\' is treated as path separator.

并且还存在术语解释差异。 path.Match():

term:
    '*'         matches any sequence of non-/ characters
    '?'         matches any single non-/ character

filepath.Match():

term:
    '*'         matches any sequence of non-Separator characters
    '?'         matches any single non-Separator character

关于go - path.Match 和 filepath.Match 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50637904/

相关文章:

linux - 为什么在 cp 命令中使用 globbing 时出现 "omitting directory"错误?

templates - 如何将变量传递给模板并在 beego 中接收变量

testing - Golang 与 Martini : Mock testing example

php - 使用 foreach 循环包含文件夹中的文件 - 不起作用。为什么?

php - glob 函数中的 RegEx 模式

php glob 获取正确的路径

python - Glob按日期顺序搜索文件?

html - 使用 golang 的 DataTable 中的动态 URL

go - 我如何在golang中将字符串转换为整数

go - 在golang中动态解码yaml