【问题标题】:How to check if a file exists如何检查文件是否存在
【发布时间】:2017-06-11 19:43:32
【问题描述】:

所以我的问题基本上是如果找不到作为参数给出的文件,我无法找出给出错误消息的条件。

if ARGV.empty?
    puts "Give me a file!"
elseif [condition]
    puts "Can't find the file"
else
    file = File.open(ARGV[0])

我真正需要的是 elseif 的条件。

【问题讨论】:

标签: ruby


【解决方案1】:

试试File.exist?,例如

2.3.0 :003 > File.exist? 'foo'
 => false 

【讨论】:

    猜你喜欢
    • 2011-11-01
    • 2011-10-21
    • 2017-04-24
    • 2013-03-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多