[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Comparing 2 files.

Aaron Scott

6/26/2008 4:04:00 PM

I'm very new to Ruby. I'm wondering if it is possible to compare 2 text fi=
les and if those files have any differences in them that I can then automat=
ically send myself an email stating that the 2 files are not the same. Tha=
nks for any help. I tried using ruby_diff but I don't think it will work f=
or my purposes.

Aaron



3 Answers

Tim Hunter

6/26/2008 4:24:00 PM

0

Aaron Scott wrote:
> I'm very new to Ruby. I'm wondering if it is possible to compare 2 text
> files and if those files have any differences in them that I can then
> automatically send myself an email stating that the 2 files are not the
> same. Thanks for any help. I tried using ruby_diff but I don't think
> it will work for my purposes.
>
> Aaron

>ri FileUtils#compare_file
------------------------------------------------- FileUtils#compare_file
compare_file(a, b)
------------------------------------------------------------------------
Returns true if the contents of a file A and a file B are
identical.

FileUtils.compare_file('somefile', 'somefile') #=> true
FileUtils.compare_file('/bin/cp', '/bin/mv') #=> maybe false


(also known as identical?, cmp)
--
Posted via http://www.ruby-....

Dave Bass

6/26/2008 4:29:00 PM

0

Aaron Scott wrote:
> I'm wondering if it is possible to compare 2 text
> files and if those files have any differences in them that I can then
> automatically send myself an email stating that the 2 files are not the
> same.

The first thing you could try is to stat the files (builtin File::Stat
class) and see if there are any relevant differences between them (e.g.
size, mtime).

Or you could ask the OS to do a diff on the files.

Or you could read each file into a string and compare the two strings.

Or...
--
Posted via http://www.ruby-....

Aaron Scott

6/26/2008 7:03:00 PM

0

Thanks That worked perfectly.

Aaron Scott
Help Desk Technician
MedAlliance Management Group, Inc.
Waterbrooke Professional Park
2312 Knob Creek Road, Suite 200
Johnson City, Tennessee 37604
Phone: 423.915.1126 x 18
Fax: 423.915.0635
Web: www.medalliance.md
-----Original Message-----
From: rmagick@gmail.com [mailto:rmagick@gmail.com]
Sent: Thursday, June 26, 2008 12:24 PM
To: ruby-talk ML
Subject: Re: Comparing 2 files.

Aaron Scott wrote:
> I'm very new to Ruby. I'm wondering if it is possible to compare 2 text
> files and if those files have any differences in them that I can then
> automatically send myself an email stating that the 2 files are not the
> same. Thanks for any help. I tried using ruby_diff but I don't think
> it will work for my purposes.
>
> Aaron

>ri FileUtils#compare_file
------------------------------------------------- FileUtils#compare_file
compare_file(a, b)
------------------------------------------------------------------------
Returns true if the contents of a file A and a file B are
identical.

FileUtils.compare_file('somefile', 'somefile') #=3D> true
FileUtils.compare_file('/bin/cp', '/bin/mv') #=3D> maybe false


(also known as identical?, cmp)
--
Posted via http://www.ruby-....