require 'json' require 'fileutils' r = Dir["../data/draft-*.txt"] r = r.to_a.map! { |s| File.basename(s) } FileUtils.touch('list.json') f = File.open('list.json', 'w') JSON.dump(r, f) f.close