Ruby现在有Dir.empty?
个,这让它变得非常简单:
Dir.empty?('your_directory') # => (true|false)
在Rubies 2.4.0之前的版本中,你可以得到一个条目列表,自己看看它是否为空(考虑到"."和".".见the docs.
(Dir.entries('your_directory') - %w{ . .. }).empty?
# or using glob, which doesn't match hidden files (like . and ..)
Dir['your_directory/*'].empty?
Update: the first method above used to use a regex; now it doesn't (obviously). Comments below mostly apply to the former (regex) version.