Geeedas Geeedas - 1 year ago 95
Ruby Question

How to count empty range on csv files in one folder?

Suppose I have 7 CSV files in one folder two of them are empty on [2..-1] range, how do I count them and get answer 2?

Answer Source

This code iterates over the csv files in current folder, opens them, and checks that every cell in the 3rd, 4th, 5th... columns are empty in every line.

separator = ";"

empty_count = Dir["*.csv"].count do |csv|
  File.readlines(csv).all? do |line|
    line.split(separator,-1).drop(2).all? do |cell|
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download