Skip to content

Instantly share code, notes, and snippets.

@nakajijapan
Created April 18, 2012 04:19
Show Gist options
  • Save nakajijapan/2411085 to your computer and use it in GitHub Desktop.
Save nakajijapan/2411085 to your computer and use it in GitHub Desktop.
[private] search image number by diretory
# config data
#dir_path = '/home/hogemoge/'
# change dir
Dir.chdir(dir_path)
p Dir.pwd
analyze = Hash.new
Dir.open(dir_path).each_with_index do |f, index|
next if f == '..'
next if f == '.'
next if File::ftype(f) == 'link'
analyze[f] = Hash.new
#--------------------
# Directory
#--------------------
dirs = %w( hoge moge age shige )
dirs.each do |dir|
analyze[f][dir] = 0
begin
Dir.open("#{f}/public/img/#{dir}/").each do |ff|
next if ff =~ /^(ignore_idr|\.\.|\.)$/
analyze[f][dir] += 1
end
rescue
next
end
#p " #{dir} = #{analyze[f][dir]}"
end
p "#{index}, #{f}," + analyze[f].values.join(',')
end
total = {}
keys = %w( hoge moge age shige )
keys.each { |key| total[key] = 0 }
analyze.each do |user, data|
data.each do |dir, count|
total[dir] += count
end
end
p "---------------------------------------------------------------------"
p "Hostname = " + `hostname`.chop
p total
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment