From: "Thibaut Barrère" Date: 2008-08-29T19:56:05+09:00 Subject: Computing folder size - do you have something cleaner than this ? Hi guys, I'm computing an approximate folder size by summing the sizes of its files, recursively, with the following code: def item_size(name) if File.directory?(name) (Dir.entries(name) - ['.','..']).inject(0) { |sum,file| sum + item_size(File.join(name,file)) } else File.size(name) end end Another version would be: def item_size_2(name) Dir[name+'/**/*'].inject(0) { |sum,file| sum + (File.directory? (file) ? 0 : File.size(file)) } end can anyone think of a shorter or more readable way of writing it ? Do you know a library that would do this ? cheers, Thibaut Barrère / LoGeek -- http://blog.logeek.fr - learning content for developers http://evolvingworker.com - tools for a better day