shell - 使用 TCL 的 tk_getOpenFile 压缩多个文件

标签 shell compression tcl

我正在 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/

相关文章:

c - Speex 解码后的帧与原始帧不同

tcl - 为什么使用 "after 0"而不是直接运行命令?

oop - 如何将一个类的 itcl 对象传递给另一个类的对象并使用所传递对象的功能?

macos - Mac OS X 10.4+ 上的 Bash 配置

linux - 文件被复制并重命名,但我也收到错误

c# - 在c#中搜索支持rar格式的压缩库

tcl - TCL的通用字符串引用

bash - 在脚本文件中运行定义的函数时找不到命令

linux - Concat 2变量并使用该变量使用shell脚本从属性文件中获取值

algorithm - 字符串的压缩算法