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.
F8ed11b903fcd3f6d9b9e48ee266ed4b?d=identicon&s=25 Pieter Steyn (Guest)
on 2006-05-15 10: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.
3da82a61d5fbd74242cc6f671a5a32e4?d=identicon&s=25 Nicolas Desprès (Guest)
on 2006-05-15 10:12
(Received via mailing list)
On 5/15/06, Pieter Steyn <pieter@clue.co.za> 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?
05be5d6610e2c3f1780aa0e39e902e93?d=identicon&s=25 Farrel Lifson (Guest)
on 2006-05-15 10:15
(Received via mailing list)
File.exists?(file_name)
F8ed11b903fcd3f6d9b9e48ee266ed4b?d=identicon&s=25 Pieter Steyn (Guest)
on 2006-05-15 10:22
(Received via mailing list)
Thanks alot!

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