How to obtain the number of files in a folder, recursively, using Ruby
I have often found myself wanting to know how many files are in a folder, including files in sub-folders. I whipped up a little Ruby code for just that:
folder_to_count = "/path/to/folder" # You should change this
begin
file_count = Dir.glob(File.join(folder_to_count, '**', '*')).select { |file| File.file?(file) }.count
rescue
puts "ERROR: The number of files could not be obtained"
# typically occurs if folder_to_count does not exist
end