Ruby Get Available Disk Drives
Asked Answered
N

1

7

Can anyone tell me how I can get a list of the available disk drives in ruby? I am creating an open file dialogue and need to know! Thanks in advance, ell.

Norval answered 15/7, 2010 at 18:8 Comment(2)
Is this on windows/linux/mac osx? If windows, check out this post: ruby-forum.com/topic/88875#170688Binge
Yes it is windows, and thank you very much, you have been of great help, I appreciate it!Norval
N
13

The article Brian gave correctly states the following code:

require 'win32ole'

file_system = WIN32OLE.new("Scripting.FileSystemObject")
drives = file_system.Drives
drives.each do |drive|
  puts "Available space: #{drive.AvailableSpace}"
  puts "Drive letter: #{drive.DriveLetter}"
  puts "Drive type: #{drive.DriveType}"
  puts "File system: #{drive.FileSystem}"
  puts "Is ready: #{drive.IsReady}"
  puts "Path: #{drive.Path}"
  puts "Root folder: #{drive.RootFolder}"
  puts "Serial number: #{drive.SerialNumber}"
  puts "Share name: #{drive.ShareName}"
  puts "Total size: #{drive.TotalSize}"
  puts "Volume name: #{drive.VolumeName}"
end
Norval answered 15/7, 2010 at 18:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.