0

I want to read all files containing .sdc The folder includes

alpha.sdc
beta.sdc
gamma.rpt

I try cmd

set a [open "proj/plrs/*.sdc" r]

but it not working

Cuong Le
  • 3
  • 2

1 Answers1

2

@Andreas has the right ideas.

set files [glob proj/plrs/*.sdc]
set combined ""
foreach file $files {
    set fh [open $file r]
    append combined [read $fh]
    close $fh
}

To use the glob characters with cat, you'll need a shell to interpret them:

set combined [exec sh -c {cat proj/plrs/*.sdc}]

or expand the results of glob

set combined [exec cat {*}[glob proj/plrs/*.sdc]]

You could use tcllib

package require fileutil
set combined [fileutil::cat {*}[glob proj/plrs/*.sdc]]

Note that glob doesn't sort the files like the shell does, so you may want

set files [lsort [glob $pattern]]
glenn jackman
  • 238,783
  • 38
  • 220
  • 352