2012-05-25

Ruby : 특정 디렉토리 밑에 있는 파일중에 200MB 넘는 파일 찾기

다음은 특정 디렉토리 아래에 있는 파일 중에서 200MB 넘는 파일을 찾아서, 크기로 정렬하여 출력하는 프로그램이다. 어려운 것은 아니지만, 필요할 때 찾아보면 좋을 듯 하여~ ^^

# -*- coding: cp949 -*-
require 'find'

$TARGET     = "C:\\"
$SIZE_LIMIT = 200_000_000

start_time = Time.now

puts "Script Start..."
puts "=========================================================================\n\n"

file_list = Array.new
Find.find($TARGET) do |path|
  if File.file?(path) and File.size(path) > $SIZE_LIMIT
    file_size = File.size(path)
    file_list << file_size.to_s + "|" + path
  end
end


file_list = file_list.sort do |a, b| 
  (a_size, a_file) = a.split(/\|/)
  (b_size, b_file) = b.split(/\|/)
  b_size.to_i <=> a_size.to_i
end


file_list.each do |file|
  (f_size, f_path) = file.split(/\|/)
  print f_size + " -> " + f_path + "\n"
end


end_time = Time.now


puts "\n\n========================================================================="
puts "Start Time : #{start_time}"
puts "End Time   : #{end_time}"

puts "Script End..."

댓글 없음:

댓글 쓰기