How do I compare two files in Ruby 1.9?
Asked Answered
B

2

24

In Ruby 1.8, I would call File.compare() from the "ftools" library to easily compare the contents of two files.

However, in Ruby 1.9, "ftools" is replaced by "fileutils", which doesn't have a "compare" method. What's the equivalent call?

Bushweller answered 23/11, 2011 at 23:16 Comment(0)
B
29

Ahh, the method has been renamed to compare_file in FileUtils.

There's also an alias of "cmp" in both versions.

Bushweller answered 23/11, 2011 at 23:19 Comment(0)
A
20

Old question, but I just got here from google. identical? is available for those who like me prefer that coding style.

FileUtils.identical?(exp, act)
Alpestrine answered 22/9, 2015 at 22:19 Comment(3)
It worked like a charm for me, I used it to make a comparison in RSpec contextOstosis
if file1 is identical to file2 you can write expect(FileUtils).to be_identical(file1, file2)Detradetract
Don't confuse this with File#identical?, which only checks, if the files are actually the same physical files on the drive.Skewback

© 2022 - 2024 — McMap. All rights reserved.