Tcl如何使用文件属性命令改变权限?

Tcl how to use file attributes command to change permissions?

我想设置file attributes,当用户双击以写入模式打开(默认)的文件时,我想将其更改为只读。

set f [open "mydata.csv" a+]
file attributes "mydata.csv" -readonly 

当运行这样时,文件的属性是一样的。只读旁边没有X或V。

知道我做错了什么吗?

您还需要传递值以设置该属性,否则您将只是读取该值(这是一个常见的 Tcl 惯用语)。在这种情况下,-readonly 属性是布尔值,因此您可以这样做来启用它:

file attributes "mydata.csv" -readonly true

要禁用它,您可以这样做:

file attributes "mydata.csv" -readonly false

(您可以使用 Tcl 解释为布尔值的任何值;1onyes 都是 true 和 [=17= 的别名]、offno都是false的别名。)