require 'pp' t_dir = 'card_dir' list = File.readlines('random_pick_up/word_new2.csv') contents = {} list.each do |line| word, time = line.chomp.split(',') contents[word] = time end Dir.entries(t_dir)[2..-1].each do |file| next if file[-1] == '~' word = file.split('.')[0] t_stamp =File.stat(File.join(t_dir, file)).birthtime.strftime("%Y/%m/%d %H:%M") puts word if contents.include?(word) contents[word] = t_stamp p word end if contents[word]==nil p contents[word] = t_stamp end end pp contents.size File.open('tmp.csv','w') do |file| contents.each_pair do |key, val| if val == nil file.print "#{key}\n" else file.print "#{key},#{val}\n" end end end