Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recursively getting the size of a directory

Is there a good gem for getting recursively calculated directory sizes? In unix, I can use du, but I want a library that absorbs the difference among OS.

like image 544
sawa Avatar asked Feb 19 '12 23:02

sawa


1 Answers

This seems to work:

Dir.glob(File.join(dir, '**', '*'))
  .map{ |f| File.size(f) }
  .inject(:+)
like image 145
yegor256 Avatar answered Sep 28 '22 17:09

yegor256