다음은 특정 디렉토리 아래에 있는 파일 중에서 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..."
'Language > Ruby' 카테고리의 다른 글
Ramaze Simple Tutorial (with Sequel) (0) | 2012.11.19 |
---|---|
Ruby : 여러 디렉토리의 사이즈를 구하고 크기 순으로 정렬하기 (0) | 2012.06.14 |
JRuby 1.6.6 인코딩 관련 버그 (0) | 2012.02.13 |
JRuby, 1.9.x 를 디폴트로 사용하기 (0) | 2011.10.27 |
Ruby : 파일(디렉토리)이름에 특정 문자열이 포함된 목록 출력하기 (0) | 2011.10.27 |