Check if directory is empty in Ruby

前端 未结 6 696
太阳男子
太阳男子 2020-12-14 15:57

How can I check to see if a directory is empty or not in Ruby? Is there something like:

Dir.exists?(\"directory\")

(I know that that functi

6条回答
  •  無奈伤痛
    2020-12-14 16:01

    Not straightforward but works perfect in *nix kind of systems.

    Dir.entries(directory_path) == ['.', '..']
    

提交回复
热议问题