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\\")
1 comment:
Sabu,
So I see you into technical stuff! Sabu, we stayed at the Aida Tourist Home, located near the KSATC (Kerala state) bust stand. Its phone number is 04865-230542. It's a basic hotel - nothing fancy but the price was good and it was convenient since it was near the bus. The people were friendly. Melissa
Post a Comment