CSV文件
我在一个目录中有1000个文件。我想调用该目录中的所有CSV文件并执行if
条件。如果条件满足,则应打印name
否则应打印"nothing"
csv示例:
name,id,address,country,food
A,11,bcvhcbdc,india,biryani
...
require "csv"
path="/logs/*exception_evaluation_summary.csv"
#calling csv files in the directory
Dir.glob(path).each do |f|
#reading csv files
csv = CSV.read(f, :headers=>true, :encoding => "bom|utf-8")
csv.each do |record|
if (record['id'] != 0 && record['country']=="india" && record['food']=="biryani")
print record[name]
else
print "nothing"
end
end
end