Browse the Ruby on Rails Community.

You are here: Forums Ask a Rails expert Get disk info...

Replytotopic

Get disk info

Posted in Forums : Ask a Rails expert

 
Profile

Authority 0
Posting Rating 15
Sign in to rate this post

Hello

I would like to know how can I can the available space from a given drive using Ruby.

Thanks
regards.

 
Profile

Authority 12
Posting Rating 78
Sign in to rate this post

if you’re running a UNIX system, you can try this for a pretty basic output:

system(‘df -h’)

 
Profile

Authority 0
Posting Rating 15
Sign in to rate this post

Thanks but my application will run on a windows platform…

Any idea how can I do this?

 
Profile

Authority 0
Posting Rating 15
Sign in to rate this post

Ok, I have the solution for windows environment.

Here it goes:

require ‘win32ole’
...

wmi = WIN32OLE.connect(“winmgmts://./root/cimv2”)
drive = @targetdir[0..1]
disk = wmi.ExecQuery(“Select * from Win32_LogicalDisk”)
disk.each do |d| freebytes = d.FreeSpace puts ”-> ” + freebytes.to_s
end

Replytotopic

Other Recent Topics

Ask a Rails expert : calling functions from model to controller

Ask a Rails expert : calling functions from model to controller

Ask a Rails expert : rspec examples?

Ask a Rails expert : Radio buttons with Observe field

Ask a Rails expert : copy to clipboard

Ask a Rails expert : url_for

Ask a Rails expert : API call problem

Ask a Rails expert : Invoke a plugin from a plugin?

Ask a Rails expert : Restful problem

Ask a Rails expert : using $F

Formatting Help
  • *bold*       _italics_      
    bq. (quotes)
  • "DSC":http://www.dsc.net
  • * or # (lists)
or cancel