Skip to content

Instantly share code, notes, and snippets.

@kirkelifson
Created June 2, 2017 21:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kirkelifson/368df0d81909486951e8fac18618cc79 to your computer and use it in GitHub Desktop.
Save kirkelifson/368df0d81909486951e8fac18618cc79 to your computer and use it in GitHub Desktop.
Reports remaining drive space for each specified drive (Windows)
require 'filesize'
require 'win32ole'
drive_list = ["D:", "H:"]
file_system = WIN32OLE.new("Scripting.FileSystemObject")
drives = file_system.Drives
drives.each do |drive|
next unless drive_list.include? drive.Path
file = File.open("#{drive.Path}//drive_status.txt", "w")
file.puts "Available space: #{Filesize.from("#{drive.AvailableSpace} B").to_s('GB')}"
file.print "Total size: #{Filesize.from("#{drive.TotalSize} B").to_s('GB')}"
file.close
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment