Ruby way to find free space on drive?

Hi Everyone,

Is there a “ruby way” to find the free space on a drive. I checked
the archives, but all I found was some talk of this 2 years ago, and
the solution was to use the win32api. I am using 1.8.1-11 prag-prog
install for windows.

I know I can do :
/\s([\d,]+) bytes free/m =~ dir f:
puts $1.split(’,’).join.to_i

and that does work, but there seems like there should be a better way
that I am missing. I can see myself needing to run this on a Unix
box fairly soon as well.

Thanks,

Walt

···

Walter Szewelanczyk
IS Director
M.W. Sewall & CO. email : walter@mwsewall.com
259 Front St. Phone : (207) 442-7994 x 128
Bath, ME 04530 Fax : (207) 443-6284


walter@mwsewall.com wrote in message news:405833D6.27159.9D31F7@localhost

Hi Everyone,

Is there a “ruby way” to find the free space on a drive. I checked
the archives, but all I found was some talk of this 2 years ago, and
the solution was to use the win32api. I am using 1.8.1-11 prag-prog
install for windows.

I know I can do :
/\s([\d,]+) bytes free/m =~ dir f:
puts $1.split(‘,’).join.to_i

The best way would use the Win32API module, or a C extension.
Otherwise, you’ll have to resort to parsed output as you’ve done here.

and that does work, but there seems like there should be a better way
that I am missing. I can see myself needing to run this on a Unix
box fairly soon as well.

See the “filesystem” package somewhere at
http://www.enteract.com/~mghall.

Regards,

Dan

WMI is the most correct way to do this on windows networks.

require ‘win32ole’
wmi = WIN32OLE.connect(“winmgmts://./root/cimv2”)
disk = wmi.ExecQuery(“Select * from Win32_LogicalDisk”)
disk.each {|drive| puts “#{drive.DeviceID} #{drive.FreeSpace}”}

walter@mwsewall.com wrote in message news:405833D6.27159.9D31F7@localhost

···

Hi Everyone,

Is there a “ruby way” to find the free space on a drive. I checked
the archives, but all I found was some talk of this 2 years ago, and
the solution was to use the win32api. I am using 1.8.1-11 prag-prog
install for windows.

I know I can do :
/\s([\d,]+) bytes free/m =~ dir f:
puts $1.split(‘,’).join.to_i

and that does work, but there seems like there should be a better way
that I am missing. I can see myself needing to run this on a Unix
box fairly soon as well.

Thanks,

Walt


Walter Szewelanczyk
IS Director
M.W. Sewall & CO. email : walter@mwsewall.com
259 Front St. Phone : (207) 442-7994 x 128
Bath, ME 04530 Fax : (207) 443-6284


djberg96@hotmail.com (Daniel Berger) wrote in message news:6e613a32.0403171652.428450da@posting.google.com

walter@mwsewall.com wrote in message news:405833D6.27159.9D31F7@localhost

Is there a “ruby way” to find the free space on a drive. I checked
the archives, but all I found was some talk of this 2 years ago, and
the solution was to use the win32api. I am using 1.8.1-11 prag-prog
install for windows.
The best way would use the Win32API module, or a C extension.

For example:

GetDiskFreeSpaceEx = Win32API.new(“kernel32”, “GetDiskFreeSpaceEx”,
[‘p’,‘p’,‘p’,‘p’], ‘i’)

def get_disk_free_space(path)
free_caller = " " * 8
total = " " * 8
free = " " * 8
GetDiskFreeSpaceEx.call(path, free_caller, total, free)
l,h = free_caller.unpack(“II”)
l + (h << 32)
end

puts get_disk_free_space(“C:”)