Roger
Roger

Reputation: 29

foreach command in tcl to read a file

I have 6 files in a directory; A.v, A.def, B.v, B.def, C.v, C.def.

I want to read the A.v and A.def files at once and go to B.v and B.def and so on. I am using the following snippet to carry out the above-said function but it is throwing errors.

foreach i [glob "./*.v"] {
    read_verilog $i.v
    read_def $i.def
}

I would like to set the variable to read just the name A, B, C etc.

Upvotes: 1

Views: 1171

Answers (1)

glenn jackman
glenn jackman

Reputation: 247210

You want to use the file rootname command here:

foreach file [glob -nocomplain "./*.v"] {
    read_verilog $file
    read_def [file rootname $file].def
}

Upvotes: 1

Related Questions