命令 glob:类型

Command glob : type

这是我的命令:

foreach fic [glob -nocomplain -dir $dir -types {f d r} *] {
    set infofile [list [file tail $fic] [file mtime $fic] [file atime $fic]]
    # ...
}

只有我有一个错误:无法读取目录“/Users/...”权限被拒绝...
我的解决方案是添加此命令:file readable

foreach fic [glob -nocomplain -dir $dir -types {f d} *] {
    if {![file readable $fic]} continue
    set infofile [list [file tail $fic] [file mtime $fic] [file atime $fic]]
    # ...
}

我以为我加r类型的时候并没有出现这种错误。
这是对文档的误解?

Windows 上的权限很复杂,以至于您只能在成功打开文件进行阅读后才能真正确定自己是否有权立即读取文件。 globfile readable 中的指示不是确定的。其他操作系统就是这种情况,并且在任何情况下都存在竞争条件:用户可以在检查 file readable 和调用其他操作之间更改权限。因此,虽然您可以使用 glob -type r,但您不应该依赖它。根本不能保证是正确的。

解决这个问题?正确处理调用错误。

foreach fic [glob -nocomplain -dir $dir -types {f d r} *] {
    try {
        # More efficient than calling [file mtime] and [file atime] separately
        file stat $fic data
    } on error {} {
        # Couldn't actually handle the file. Ignore
        continue
    }
    set infofile [list [file tail $fic] $data(mtime) $data(atime)]
    # ...
}