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
You can use entries to see all files and folders in a directory:
Dir.entries('directory')
=> ['.', '..', 'file.rb', '.git']
Dir.entries('directory').size <= 2 # Check if empty with no files or folders.
You can also search for files only using glob:
Dir.glob('directory/{*,.*}')
=> ['file.rb', '.git']
Dir.glob('directory/{*,.*}').empty? # Check if empty with no files.