Skip to content

Instantly share code, notes, and snippets.

@deathwishdave
Last active August 29, 2015 14:22
Show Gist options
  • Save deathwishdave/53562c3d9417893e6cc1 to your computer and use it in GitHub Desktop.
Save deathwishdave/53562c3d9417893e6cc1 to your computer and use it in GitHub Desktop.
require 'find'
require 'pathname'
class SharedFile
attr_reader :file_name
attr_reader :file_size
def initialize(path, file_size)
#@path = path
@file_name = Pathname.new(path).basename
@file_size = file_size
end
def ==(other)
self.file_name == other.file_name && self.file_size == other.file_size
end
def eql?(other)
self == other
end
def hash
[file_name, file_size].hash
end
end
files = []
Find.find(".") do |path|
files << SharedFile.new(path,File.size(path)) #if path =~ /.*\.pdf$/
end
results = files.group_by{|file| file}.map{|k,v| [k,v.count] }
# puts results[1].inspect
results.each do |result|
puts "#{result[0].file_name}, #{result[0].file_size}, #{result[1]}" if result[1] > 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment