如何检查目录是否为空?

时间:2015-03-11 16:00:58

标签: tcl expect

我知道期待的是tcl-in-sheep-s-clothing,但即使我记得这一点,我也会空着。

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

2 个答案:

答案 0 :(得分:4)

使用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"
}

答案 1 :(得分:0)

使用:

[glob -nocomplain -dir $dir *]

而不是

[glob -nocomplain "$dir/*"]

如果您在某些情况下未指定目录,则命令将失败(例如我的Windows 8.1 with Tcl8.6)。指定该命令可在Windows和Linux中正常运行。

相关问题