Skip to content

Instantly share code, notes, and snippets.

@mobp
Created June 1, 2010 22:41
Show Gist options
  • Save mobp/421637 to your computer and use it in GitHub Desktop.
Save mobp/421637 to your computer and use it in GitHub Desktop.
重複ファイルの削除
class Comp
def initialize ext
@file_ext = ext
end
def compare n
len = Dir::glob(self.file_ext).length
if n+1 == len || len == 0
return 0
end
src = open(Dir::glob(self.file_ext)[n])
Dir::glob(self.file_ext)[n+1..len].each do |f|
begin
src2 = open(f)
if src.stat.size == src2.stat.size
begin
if src.read == src2.read
File::delete(f)
if n == 0
self.compare 0
else
self.compare n - 1
end
end
rescue
end
end
rescue
end
end
self.compare n + 1
end
attr_reader :file_ext
end
class RecurseDir
def initialize(path)
@dir = Array::new #後でたどるディレクトリ
Dir::foreach(path) do |s|
if File::ftype(s) == "directory"
if s != ".."
self.dir << File::expand_path(s)
end
end
end
end
def recurse_compare
self.dir.each do |f|
p f + "/*"
a = Comp::new f + "/*"
a.compare 0
end
end
attr_reader :dir
end
a = RecurseDir.new "./"
a.recurse_compare
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment