I’ve been using File.compare to see if two files are the same, but now i
have the case where one is a renamed copy of the other. I’d like to
treat these two as the same in this case. Can anyone suggest a test
that doesn’t care about names?
The files that have been renamed are xml (ie text format) if that makes
life easier but a solution that works with binaries as well would be
ideal.
I’ve been trying to google checksums in ruby but haven’t seen a useful
example, maybe i was just being blind. Will a checksum ignore the name
of the file?
I’ve been trying to google checksums in ruby but haven’t seen a useful
example, maybe i was just being blind. Will a checksum ignore the name
of the file?
google for Ruby digest. A SHA1 hash is a good alternative.
require ‘digest/sha1’
def contents_equal?(path_to_file_1, path_to_file_2)
Digest::SHA1.file(path_to_file_1).hexdigest ==
Digest::SHA1.file(path_to_file_2).hexdigest
end
Hmmm (tests) - no Siep, you’re right. Looks like the two files i
thought were the same weren’t after all. Which is a problem, since the
second one is supposed to be a renamed copy of the first. Looks like i
need to go back a step here.
I’ve been using File.compare to see if two files are the same, but now i
have the case where one is a renamed copy of the other. I’d like to
treat these two as the same in this case. Can anyone suggest a test
that doesn’t care about names?
The files that have been renamed are xml (ie text format) if that makes
life easier but a solution that works with binaries as well would be
ideal.
I’ve been trying to google checksums in ruby but haven’t seen a useful
example, maybe i was just being blind. Will a checksum ignore the name
of the file?
thanks
max
Hmm? File.compare does not care about names, the content of the files is
compared.