如何检查目录是否为空?

Joh*_*n O 2 tcl expect

我知道 expect 是 tcl-in-sheep's-clothing,但即使我在谷歌上考虑到这一点,我也是空的。

有没有办法确定特定目录是否为空(或不为空,我可以使用否定)?

Din*_*esh 5

使用glob,尝试搜索其中的模式*

set dir "/home/dinesh/stack"
set file_list [glob -nocomplain "$dir/*"]
if {[llength $file_list] != 0} {
    puts "$dir is not empty"
} else {
    puts "$dir is empty"
}
Run Code Online (Sandbox Code Playgroud)