Feature #10121

Dir.empty?

Added by Robert A. Heiler 11 months ago. Updated 10 months ago.

[ruby-core:64291]
Status:Feedback
Priority:Normal
Assignee:-

Description

On IRC someone asked how to find out if a directory is empty or not, from within ruby.

It seems as if there was no simple way.

I suggest adding Dir.empty?

On IRC, someone else suggested this:

Dir.entries(dir).size == 2

I do not know if there are better ways but possibly that could
be used for a Dir.empty? functionality?

History

#1 Updated by Nobuyoshi Nakada 10 months ago

  • Description updated (diff)
  • Category set to core
  • Status changed from Open to Feedback

What should happen if the dir is not a directory name?
Just returns false, or raises Errno::ENOTDIR?

Also available in: Atom PDF