-1

我有这样的代码:

...
proc myProc {first last} {
    for { set i $first } { $i <= $last } { incr i } {
        set i_cur "PlainText$i"
        <command> [glob ./../myDir/${i_cur}*]
    }
}

当我运行它时,任何在数字之后没有任何内容的文件都可以正常运行。但如果数字后面有什么东西,那就没有了。例如,我有名为PlainText0.txtPlainText00.txt和的有效文件PlainText1_Plaintext.txt。前两个工作,PlainText1_Plaintext.txt没有。

基本上,我认为我没有正确使用全局/通配符,但不知道如何。

4

1 回答 1

1

这类事情的常见问题是当你得到你想要的错误的 glob 时,或者当你有一个需要扩展返回的列表的命令时。glob

如果是该命令需要扩展列表,则需要使用:

<command> {*}[glob ...]

{*}括号前面的那个将结果扩展为多个参数。有时,这需要您迭代结果并一次传递它们:

foreach filename [glob ...] {
    <command> $filename
}

当涉及到 glob 本身时,您不太清楚PlainText1_stuff.txt您是否可以接受。但是,它与 pattern 匹配PlainText1*。如果不能接受,也许你需要PlainText1.*;额外.的对于这里匹配的内容很重要。

此外,请考虑使用该-directory选项,glob因为它可以使您的代码更清晰(尤其是如果您在允许文件名中包含 glob 元字符的平台之一上)。


总体而言,您可能正在查看以下内容:

<command> {*}[glob -directory ../myDir PlainText$i.*]

如果需要,您可以使用辅助变量。

于 2016-10-20T08:09:09.290 回答