4

So my problem is basically is that I can't figure out a condition to give an error message if can't find the file given as argument.

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

What I exactly need is the condition for the elseif.

David Grayson
  • 84,103
  • 24
  • 152
  • 189
M. Adam
  • 53
  • 1
  • 5

1 Answers1

11

Try File.exist?, e.g.

2.3.0 :003 > File.exist? 'foo'
 => false 
Andy Gaskell
  • 31,495
  • 6
  • 74
  • 83