Hi,
How would you do this the ruby-way ?
I want to program a little tool with ruby, which find duplicate files
on filesystems.
Currently I have a hash, which key is the fully qualified
pathname/file and its value is the md5sum (by the way: Is there a
md5sum-generator inside Ruby ?) of that file.
It is possible, that a certain md5sum is stored multiple times as
hash value.
To find, whether there are duplicated files at all I did (fphash is
the hash mentioned above):
ifphash=fphash.invert
if( ifphash.length != fphash.length )
p "Duplicates indicated!"
end
This is quite simple, a little brute force and fast.
But now the tricky part, for which I do not have a solution beside
the step by step method, which works with nearly every programming
language.
WHICH files are duplicated ?
The “invert” deletes the information except of one file, since all
now duplicated keys are deleted.
fparr=fphash.values
fparr.uniq!
did quite the same thing.
Methods like has_value? and has_key? only returns a boolean value but
not the corresponding item(s).
Is there a method or ruby-“trick” to solve the problem ?
Thank you very much in advance for any help and/or hint !
Have a nice weekend!
Meino Cramer
Dont worry, be ruby!
I like rubymental programming !