Forum: Ruby Test if file exists

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Pieter S. (Guest)
on 2006-05-15 12:06
(Received via mailing list)
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.
Nicolas Desprès (Guest)
on 2006-05-15 12:12
(Received via mailing list)
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?
Farrel L. (Guest)
on 2006-05-15 12:15
(Received via mailing list)
File.exists?(file_name)
Pieter S. (Guest)
on 2006-05-15 12:22
(Received via mailing list)
Thanks alot!

That's so simple, hehe!
This topic is locked and can not be replied to.