Created
June 2, 2017 21:55
-
-
Save kirkelifson/368df0d81909486951e8fac18618cc79 to your computer and use it in GitHub Desktop.
Reports remaining drive space for each specified drive (Windows)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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