From: "Matthew B." Date: 2010-11-20T04:30:36+09:00 Subject: Re: Is there a ruby way to get the disk size of a directory? For the web archive :) my slightly shorter effort, possibly more portable, is attached. It relies on libffi being installed: module Linux; module StatFs # The result of a statfs operation, see "man statfs" for more information # on each field. We add some helper methods that deal in bytes. # class Result < Struct.new(:type, :bsize, :blocks, :bfree, :bavail, :files, :ffree) def total; blocks * bsize; end def free; bfree * bsize; end def avail; bavail * bsize; end end module Lib extend FFI::Library ffi_lib FFI::Library::LIBC attach_function 'statfs64', [:string, :pointer], :int end # Drives the interface to the C library, returns a StatFs::Result object # to show filesystem information for the given path. # def self.statfs(path) output = FFI::MemoryPointer.new(128) begin error_code = Lib::statfs64(path, output) raise "statfs raised error #{error_code}" if error_code != 0 return Result.new(*output[0].read_array_of_long(7)) ensure output.free end end end; end I've only tested it to see that the results tally with "df", so e.g. to find the number of free bytes on your root, you run: Linux::StatFs.statfs(".").free Regards, -- Matthew Bloch -- Posted via http://www.ruby-forum.com/.