Reputation: 5423
I'm aware that expect is tcl-in-sheep's-clothing, but even when I google with that in mind I'm coming up empty.
Is there a way to determine if a particular directory is empty (or not empty, I can just use negation)?
Upvotes: 3
Views: 3924
Reputation: 61
Use:
[glob -nocomplain -dir $dir *]
instead of
[glob -nocomplain "$dir/*"]
If you don't specify the directory in some cases your command will fail (like my Windows 8.1 with Tcl8.6). Specifying the directory the command works fine in Windows and Linux.
Upvotes: 0
Reputation: 16428
With glob
, try searching for the pattern *
in it.
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"
}
Upvotes: 5