gpt4 book ai didi

regex - 在 Go 中使用 filepath.Glob

转载 作者:IT王子 更新时间:2023-10-29 01:59:55 29 4
gpt4 key购买 nike

我在尝试理解 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 语法,也没有找到任何综合示例。

最佳答案

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

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

关于regex - 在 Go 中使用 filepath.Glob,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25164070/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com