Errno :: ENOENT没有这样的文件或目录

时间:2012-11-15 12:48:35

标签: ruby-on-rails csv

我正在使用RoR 2.3.8,我想在“路径”中读取.csv文件

def run(filepath, contact_id, filename)
        path = "#{filepath}/#{filename}"
        Rails.logger.info path
        return ["The file "+ filename +" does not exist"] unless File.exist?(path)

        CSV.foreach(File.basename(path), {:col_sep => @seperator}) do |row|

当我这样做时,我收到此错误:

Errno::ENOENT in Admin::RoutesController#status_race

No such file or directory - /Users/anna/Documents/aphroditel/route_finder/arbinet/app/importersQuickcom-Standard-20121107-FULL.csv`

但我完全确定路径是正确的,文件就在那里。我错过了什么?谢谢!

1 个答案:

答案 0 :(得分:0)

您是否在没有File.basename的情况下尝试了?

CSV.foreach(path, {:col_sep => @seperator}) do |row|