#!/usr/bin/ruby -w #author: caoqing#date: 06-04-2014require 'fileutils'# target directoryd = "D:/test"# size of file, MBquota = 4 * 1024 * 1024dir = Dir.new("#{d}")entries = dir.entries# delete "." and ".."entries.delete_if { |entry| entry =~ /^\./}# convert the relative path to the full pathentries.map! { |entry| File.join(dir.path, entry) }# maintain only the type of fileentries.delete_if { |entry| !File.file?(entry) }# p entries# calculate the file sizetotal_size = entries.inject(0) { |total, entry| total + File.size(entry)}# p total_size# p quota# p total_size.class# delete file if condition is satisfiedFileUtils.rm_rf(Dir.glob("#{d}/*")) if total_size > quot