TCL incr 文件名

TCL incr filename

我不想多次设置$outfile,我想增加文件名。 我如何在 TCL 中做到这一点?

set incr 1
set outfile [open "file$incr.txt" w]

set infile1 "[glob /a/b/c/d/a12b.txt /a/e/c/e/c123d.txt /e/e/d/e/2abd.txt ]"
set infile2 "[glob /a/b/c/d/a12b.txt /a/e/c/e/c123d.txt /e/e/d/e/2abd.txt ]"
set infile3 "[glob /a/b/c/d/a12b.txt /a/e/c/e/c123d.txt /e/e/d/e/2abd.txt ]"

foreach infile $infiles$incr {

    puts $oufile$incr "testing"

}

但是,我上面的代码似乎不起作用?

具有incr功能:

set infile {}
set i 0

lappend infile "[glob /a/b/c/d/a12b.txt /a/e/c/e/c123d.txt /e/e/d/e/2abd.txt ]"
lappend infile "[glob /a/b/c/d/a12b.txt /a/e/c/e/c123d.txt /e/e/d/e/2abd.txt ]"
lappend infile "[glob /a/b/c/d/a12b.txt /a/e/c/e/c123d.txt /e/e/d/e/2abd.txt ]"

foreach value $infile {
    incr i
    set outfile [open "file${i}.txt" w]
    foreach files $value {
        puts $outfile "testing"
    }
    close $outfile
}

另一个解决方案,你可以使用array :

set infile(1) "[glob /a/b/c/d/a12b.txt /a/e/c/e/c123d.txt /e/e/d/e/2abd.txt ]"
set infile(2) "[glob /a/b/c/d/a12b.txt /a/e/c/e/c123d.txt /e/e/d/e/2abd.txt ]"
set infile(3) "[glob /a/b/c/d/a12b.txt /a/e/c/e/c123d.txt /e/e/d/e/2abd.txt ]"

foreach {key value} [array get infile] {
    set outfile [open "file${key}.txt" w]
    foreach files $value {
        puts $outfile "testing"
    }
    close $outfile

}