在 tcl 中复制文件名(带通配符)
Copy filename (with wildcard) in tcl
我正在尝试使用通配符复制文件,但未正确解释该文件。
set projName [lindex $argv 0]
puts "$projName chosen"
set sysdefPath "$projName/$projName.runs/impl_1/*.sysdef"
file copy -force $sysdefPath ./src/generatedFiles/$projName.hdf
我已经尝试了几个变体,但 none 都奏效了 {*}、(*)、[*]、{.*}。这样做的结果是将通配符 (*) 放在搜索路径中,而不是尝试对其进行模式匹配。
执行此操作的正确方法是什么?
输出,
$ 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)
您的 shell 将在找到文件模式的任何地方展开它们。 Tcl 不是这样的:您必须使用 glob
命令明确要求匹配模式的文件列表:untested
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]"}
}
我正在尝试使用通配符复制文件,但未正确解释该文件。
set projName [lindex $argv 0]
puts "$projName chosen"
set sysdefPath "$projName/$projName.runs/impl_1/*.sysdef"
file copy -force $sysdefPath ./src/generatedFiles/$projName.hdf
我已经尝试了几个变体,但 none 都奏效了 {*}、(*)、[*]、{.*}。这样做的结果是将通配符 (*) 放在搜索路径中,而不是尝试对其进行模式匹配。
执行此操作的正确方法是什么?
输出,
$ 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)
您的 shell 将在找到文件模式的任何地方展开它们。 Tcl 不是这样的:您必须使用 glob
命令明确要求匹配模式的文件列表:untested
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]"}
}