打开带有日期和时间戳的文件 - Ruby Cucumber

Open file with date and time stamp - Ruby Cucumber

我又在处理 CSV 了!!我试图让 Cucumber 打开它,但我的问题是,每次我从正在开发的网页下载新的 CSV 文件时,它都会添加一个日期和时间戳,如下所示:

company_123456_export_all_20151007_074608.csv

有没有办法让 Cucumber 只打开最后一个?我试过:

File.open(C:/Users/**/Downloads/company_#{export}_export_all_*.csv).last

但是不喜欢,有什么建议吗?

我认为您应该阅读 ruby 中有关文件操作的更多信息。 对于您的情况,您可以尝试类似的方法:

file_name = Dir.glob("C:\/Users\/**\/Downloads\/company_#{export}_export_all_*.csv").last
file = File.open(file_name, "r")
...

其中,第一行是获取所有文件名,只取最后一个。第二行是以只读模式打开此文件。