Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excec problem

Status
Not open for further replies.

fabien

Technical User
Sep 25, 2001
299
AU
Hi!

I am trying to use Exec to get a list of files with ls, here is the code:

for {set i 0} {$i < $nbdir} {incr i} {
# puts $swdirlist($i)
#test if directory exists
if { [file isdirectory "$swdirlist($i)/$swprjsel"] } {
set cmd "$swdirlist($i)/$swprjsel/*.\[3bc\]\[drm\]\[viph\]"
set execCmd "exec ls -l $cmd"
catch { eval $execCmd } result
puts $result
# lappend seisfile $result

}
}

I get an error invalid command name "3bc". I have added \before the ['s same result

An add_on question is that I want to store the result in a string so I put lappend seisfile $result is it the best thing to do. Later on on I want to extract some specific filenames from this string.

Many thanks!
 
I found a better way to do this and it actually works:

for {set i 0} {$i < $nbdir} {incr i} {
if { [file isdirectory "$swdirlist($i)/$swprjsel"] } {
set dir "$swdirlist($i)/$swprjsel"
set pat "*.\[3bc\]\[drm\]\[viph\]"
catch { glob -nocomplain -tails -dir $dir $pat } result
puts $result
# lappend seisfile $result

}
}



}
 
Tcl has two strings syntax:
"a string"
and
{a string}

The first syntax lets Tcl interpret $var and [proc] inside the string and the second doesn't.

So it would be better to code:
set pat {*.[3bc][drm][viph]}

HTH

ulis
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top