TCL wildcard/glob usage within file name

佐手、 提交于 2019-12-01 14:48:54

The usual issues with this sort of thing are when you've got the glob for what you want wrong, or when you've got a command that needs the list returned by glob expanded.

If it's that the command needs the list expanded, you need to use:

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

That {*} in front of the bracket expands the results into multiple arguments. Sometimes, this instead requires you to iterate over the results and pass them in one at a time:

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

When it comes to the glob itself, you're not quite clear whether PlainText1_stuff.txt is acceptable to you or not. However, it is matched by the pattern PlainText1*. If it isn't acceptable, maybe you need PlainText1.*; the extra . is important to what is matched here.

Also, consider using the -directory option to glob as it makes your code clearer (especially if you're on one of the platforms that allows glob metacharacters in filenames).


Overall, you're perhaps looking at something like this:

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

You can use a helper variable if you want.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!