Nathan Pk
Nathan Pk

Reputation: 749

copying files in tcl

I have a query in "file copy" tcl command. I tried storing all my files to a list and used it in my command. But tcl is not recognizing those files.

for example:

    Files are abc.log , foo.log , bar.log

if these files are appended to a list say list_file and If I substitute the list_file in my command

    lappend list_file abc.log foo.log bar.log
    file mkdir ../../abc
    file copy -- $list_file ../../abc

I am getting an error message " error copying , no file or directory". If I try the same by directly specifying the file names (instead of list) it works. Please guide me with this

Upvotes: 2

Views: 16411

Answers (2)

kostix
kostix

Reputation: 55453

To elaborate on @evil-otto's answer...

{*} is only available since Tcl 8.5; for earlier versions either eval or multiple invocations could be used.

Constructing a command using eval:

set cmd [list file copy --]
lappend cmd abc.log foo.log bar.log ../../abc
eval $cmd

(Read this to learn why using lists is a must when creating commands to be evaluated.)

Multiple invocation (a no-brainer):

foreach fname $list_file {
    file copy -- $fname ../../abc
}

Upvotes: 3

evil otto
evil otto

Reputation: 10582

The list passed to file copy must be expanded.

file copy -- {*}$list_file ../../abc

Upvotes: 1

Related Questions