From: MonkeeSage Date: 2007-12-06T02:10:01+09:00 Subject: Re: Ruby equivalent for `du` On Dec 5, 10:51 am, Christian von Kleist wrote: > I wrote a simple method for recursively finding the size of a > directory, because I didn't see anything in File::Stat or FileUtils > that does that. Am I missing it? Does Ruby already have an > equivalent to `du`? > > def size(f) > return File.size(f) unless File.directory?(f) > Dir.entries(f)[2..-1].inject(0) {|total, s| total + size(File.join(f, s))} > end Couple problems with that approach 1.) assuming that ".", ".." are the first elements of the entries array, 2.) for deep directories you'll run out of stack very quickly. Have a look at the example at the top of the Find module. ;) [1] http://www.ruby-doc.org/core/classes/Find.html Regards, Jordan