Finding out the available disk space

I typically use df -h from the command-line however this command isn't available by default in Windows which is why I will use the following code:

require 'sys/filesystem'

stat = Sys::Filesystem.stat("/")
#=> #<Sys::Filesystem::Stat:0x9bf11f8 @path="/", @block_size=4096, @fragment_size=4096, @blocks=18432336, @blocks_free=8811516, @blocks_available=7875195, @files=4685824, @files_free=4108646, @files_available=4108646, @filesystem_id=1417283743, @flags=0, @name_max=1024, @base_type="">     
mb_available = stat.block_size * stat.blocks_available / 1024 / 1024
#=> 30762    # which means 31GB available space


Instal

ling sys-filesystem Using the command rvm 1.9.3 do gem install sys-filesystem I observed the following output:

Fetching: ffi-1.1.0.gem (100%)
Building native extensions.  This could take a while...
Fetching: sys-filesystem-1.0.0.gem (100%)
Successfully installed ffi-1.1.0
Successfully installed sys-filesystem-1.0.0
2 gems installed
Installing ri documentation for ffi-1.1.0...
unable to convert "\xCA" from ASCII-8BIT to UTF-8 for lib/ffi_c.bundle, skipping
Installing ri documentation for sys-filesystem-1.0.0...
Installing RDoc documentation for ffi-1.1.0...
unable to convert "\xCA" from ASCII-8BIT to UTF-8 for lib/ffi_c.bundle, skipping
Installing RDoc documentation for sys-filesystem-1.0.0...

Resources

Tags:
Source:
1839hrs.txt
Published:
20-07-2012 18:39