RosettaCodeData/Task/Empty-directory/Ruby/empty-directory-1.rb

6 lines
178 B
Ruby

# Checks if a directory is empty, but raises SystemCallError
# if _path_ is not a directory.
def empty_dir?(path)
not Dir.foreach(path).detect {|f| f != '.' and f != '..'}
end