looking for math

S

soldier.coder

I'm looking for code that will do some operation on a file and give me
a number that is unique to that file. if I happen to come across same
file somewhere else and the contents are the same, the same number
should be produced.

First what is that called, and anyplace i can see code that does that?
 
F

Fabio Cevasco

[Note: parts of this message were removed to make it a legal post.]

Perhaps you mean creating checksums or MD5 digests?

The code is simple, assume there's a "README.textile" file in the current
directory; just launch IRB and do the following:
____
ruby-1.9.2-p136 :001 > require "digest"
=> true
ruby-1.9.2-p136 :002 > Digest::MD5.file("README.textile").to_s
=> "fd4964756811f1590cc13efb7ac7895a"
____

For more information, see the Digest library:
http://ruby-doc.org/stdlib/libdoc/digest/rdoc/index.html

Hope it helps,

Fabio Cevasco
=======================
web: http://www.h3rald.com
twitter: http://twitter.com/h3rald




On Sun, Feb 6, 2011 at 6:30 PM, soldier.coder <
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,139
Messages
2,570,807
Members
47,356
Latest member
Tommyhotly

Latest Threads

Top