如何在TCL中的目录内而不是整个目录内复制文件?

meg*_*ery 1 tcl

由于软件升级,文件被保存到错误的目录,并且现有脚本无法正常工作,我需要对其进行修复。文件保存在项目文件中较深的几个文件夹中。我知道我可以使用此命令来复制目录

file copy -force "path_files_to_copy" "path_to_copied_into"
Run Code Online (Sandbox Code Playgroud)

这样,尽管它将复制文件夹,但路径指向的是该文件夹中而不是每个单独的文件夹和文件。如何将指定路径中的所有内容复制到新位置而不是仅复制到父位置?

编辑

我解决了它,它起作用了,尽管在我看来,我使用的步骤比完成同一目标所需的步骤多出十倍。主要将tcl产生的“ \”更改为“ \”,这会将其视为字符。

# Copy files from this folder
set from $take_from ;# Everything from this folder
set to $bring_to ;# To this folder

set var [glob -dir $from *;]
set wordList [regexp -inline -all -- {\S+} $var] ;# makes a list 
for { set i 0 } {$i < [ llength $var ] } { incr i } { ;# Loop through files found

    set file_path [ lindex $var $i ]    
    set count 0
    set indx  0
    set limit [string length $file_path]
    set file_path_f $file_path
    set incra 0

    while { $count < $limit } { 

        set t [string index $file_path $count]      

        if { "$t" == "\\" } {

            set temp $count
            set indx $temp              
            set ll [expr $count + $incra]
            set file_path_f [string replace $file_path_f $ll $ll "\\\\"]
            incr incra

        }

       incr count 

}

#                FILES              DESTINATION
file copy -force $file_path_f           $to

}
Run Code Online (Sandbox Code Playgroud)

kos*_*tix 5

使用glob命令枚举源目录下的条目,然后分别复制每个条目:

foreach f [glob -directory $sourceDir -nocomplain *] {
    file copy -force $f $targetDir
}
Run Code Online (Sandbox Code Playgroud)