Ruby's Win32OLE module can be used to do our automation tasks. Using this we will call the FileSystemObject of Windows to call functions that we need. Here is the link to MSDN info on FileSystemObject.
The following script will give us the amount of disk space in C: drive.
require 'win32ole'
fso = WIN32OLE.new("Scripting.FileSystemObject")
drv = fso.GetDrive(fso.GetDriveName("C:"))
space = ((drv.TotalSize/1024)/1024)/1024
puts "#{space} GB"
Some more samples
#Get subfolders in C:\
fldr=fso.GetFolder("C:\\")
fldrs=fldr.SubFolders
fldrs.each do |x|
puts "name is #{x.name}"
end
#Get files in C:\
fldr=fso.GetFolder("C:\\")
files=fldr.Files
files.each do |x|
puts "name is #{x.name}"
end
You can edit the code to access remote share by changing it as follows :-
fldr=fso.GetFolder("\\\\remote-machine\\share\\")