class FileCheckHelper
puts “hello cyan”.cyan puts “hello red”.red puts “hello green”.green puts “hello yellow”.yellow puts “hello blue”.blue puts “hello magenta”.magenta puts “hello brown”.brown puts “hello blanchedalmond”.blanchedalmond
Public Class Methods
new()
click to toggle source
desc “Instance”
# File lib/duplicate_file_check.rb, line 20 def initialize() end
Public Instance Methods
check(type, suffix)
click to toggle source
duplicate file check
# File lib/duplicate_file_check.rb, line 24 def check(type, suffix) # specify files which should not be copied current_dir = Dir.pwd fileNames = [] files = Dir[current_dir + "/**/*.{#{suffix}}"] files.each do |old_dest| fileNames.push(File.basename(old_dest)) end fileMaps = Hash.new([]) files.each { |filePath| key = "" if type == "md5" key = md5 = Digest::MD5.hexdigest(File.read(filePath)) elsif type == "name" key = File.basename(filePath) end fileArr = [] + fileMaps[key] fileMaps[key] = fileArr.push(filePath) } fileMaps.each {|key, value| if value.count > 1 puts "#{key} repeat count: #{value.count}".yellow fileArr = [] + value fileArr.each { |filePath| puts "#{filePath}" } end } puts "Successfully checking ...🍻🍻🍻🍻🍻...".green end