copying files in tcl

14,585

Solution 1

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
}

Solution 2

The list passed to file copy must be expanded.

file copy -- {*}$list_file ../../abc
Share:
14,585
Nathan Pk
Author by

Nathan Pk

Updated on June 14, 2022

Comments

  • Nathan Pk
    Nathan Pk almost 2 years

    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

  • Nathan Pk
    Nathan Pk over 11 years
    thanks! how to copy a directory? it says "can't overwrite file"