我正在 tcl 中创建一个打包器,用户可以从中选择要将哪些文件压缩到包中。
问题是,我无法压缩多个文件,当选择多个文件时,$file变量中的路径如下所示:“/home/file.txt/home/file2.txt”因此无法压缩因为这条路不喜欢。
有没有办法使用 tk_getOpenFile 函数压缩多个文件?
set types {
{{Text Files} {.txt} }
}
#Here i'm defining that only .txt files can be selected
set file [tk_getOpenFile -multiple 1 -filetypes $types -parent .]
#the file chooser function in tcl, where it can be chosen multiple files at once, the path of the files go into the $file variable
exec zip -j package.zip $file
# A shell script function for zipping the files
最佳答案
exec zip -j package.zip {*}$file
如果您使用的是 Tcl 8.5 或更高版本。
{*}
前缀重写调用,以便如果其后面的表达式是列表,则该列表中的每个元素都将成为调用中的一个单词。如果 $foo
的值为 {a b c}
并且您调用 bar abc {*}$foo def
,则实际调用将变为 栏 abc a b c def
.
只要保持 -multiple
选项处于打开状态,包含空格的文件名就不会有任何问题。
文档:{*}
关于shell - 使用 TCL 的 tk_getOpenFile 压缩多个文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32208622/