【问题标题】:Using filepath.Glob in Go在 Go 中使用 filepath.Glob
【发布时间】:2014-08-06 15:14:41
【问题描述】:

我在尝试理解 filepath.Glob 时遇到了这个问题

for _, v := range ListofPaths{
    exists, _ := filepath.Glob(fmt.Sprintf("%s/*/%s", v, filename))
}

适用于任何路径

ListofPathsPath/any/dot/thing/filename.ext

但不是

ListofPathsPath/filename.ext 

所以从上面我需要匹配 glob %s/%s 或 %s/*/%s

有没有办法表达这个?我还没有完全掌握 filepath.Match 语法,也没有找到任何全面的示例。

【问题讨论】:

  • ** 代替* 怎么样?

标签: regex go filepath


【解决方案1】:

这确实是基本的 shell 语法,你不能那样做。

您必须调用 glob 两次或只使用 filepath.Walk

【讨论】:

    猜你喜欢
    • 2018-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-02
    相关资源
    最近更新 更多