Test if file exists


#1

Hi,

Look at this :

if (ARGV.size != 2)
puts ‘usage: ./compare file1 file2’

else
filename1 = ARGV[0]
filename2 = ARGV[1]


How would I test if the arguments given (filename1 and 2) are actually
files
that exist?

Thanks.


#2

On 5/15/06, Pieter S. removed_email_address@domain.invalid wrote:

Hi,

Hi,

[…]

How would I test if the arguments given (filename1 and 2) are actually files
that exist?

File.exists?(filename1)

or

require ‘pathname’
Pathname.new(filename1).exists?


#3

File.exists?(file_name)


#4

Thanks alot!

That’s so simple, hehe!