Sha256: 6523c7d509a6c585e81100eaee4e6ec9794de94f78b79067f3ec1db723e4e53e
Contents?: true
Size: 843 Bytes
Versions: 79
Compression:
Stored size: 843 Bytes
Contents
#!/usr/bin/env ruby require 'utils' require 'tins/find' include Utils::MD5 def find_same(*paths) files = Hash.new { |h,k| h[k] = {} } Tins::Find.find(*paths) do |filename| file_stat = File.stat(filename) if file_stat.file? size = file_stat.size $DEBUG and warn "Encountered '#{filename}' (#{size} bytes)." files[size][filename] = true end end files = files.inject({}) do |h, (_,fs)| keys = fs.keys if keys.size >= 2 keys.each { |k| h[k] = true } end h end.keys md5s = Hash.new { |h,k| h[k] = [] } for filename in files md5sum = md5 filename md5s[md5sum] << filename end files = md5s.values files.reject! { |fs| fs.size < 2 } files end puts find_same(*ARGV).map { |fs| [ fs.size, fs ] }.sort.map { |c, fs| "#{c}\t#{fs.sort.map { |f| "'#{f}'" } * "\t"}" }
Version data entries
79 entries across 79 versions & 1 rubygems