在tcl中复制文件名(带通配符)

时间:2018-09-18 18:16:25

标签: tcl xilinx vivado

我正在尝试使用通配符复制文件,但文件解释不正确。

set projName [lindex $argv 0]
puts "$projName chosen"

set sysdefPath "$projName/$projName.runs/impl_1/*.sysdef"
file copy -force $sysdefPath ./src/generatedFiles/$projName.hdf

我已经尝试了几种变体,但都没有使用{*},(*),[*],{。*}。这样的结果将通配符(*)放置在搜索路径中,而不是尝试对其进行模式匹配。

执行此操作的正确方法是什么?

输出

$ test.tcl -tclargs proj
# set projName [lindex $argv 0]
# puts "$projName chosen"
proj chosen
# set sysdefPath "$projName/$projName.runs/impl_1/*.sysdef"
# file copy -force $sysdefPath ./src/generatedFiles/$projName.hdf
error copying "proj/proj.runs/impl_1/*.sysdef": no such file or directory
    while executing
"file copy -force $sysdefPath ./src/generatedFiles/$projName.hdf"
    (file "./src/projTcls/build_bitstream.tcl" line 5)

1 个答案:

答案 0 :(得分:3)

您的shell会在找到文件模式的任何地方扩展它们。 Tcl不是这样的:您必须使用np.select命令:未经测试

明确要求匹配模式的文件列表
set pattern $projName/$projName.runs/impl_1/*.sysdef
set sysdefPaths [glob -nocomplain -- $pattern]
switch -exact [llength $sysdefPaths] {
    0 {error "No files match $pattern"}
    1 {file copy -force [lindex $sysdefPaths 0] ./src/generatedFiles/$projName.hdf}
    default {error "Multiple files match $pattern: [list $sysdefPaths]"}
}
相关问题