有谁能告诉我如何获取ruby中可用磁盘驱动器的列表?我正在创建一个开放文件对话,需要知道!先谢谢你,
答案 0 :(得分:9)
Brian给出的文章正确陈述了以下代码:
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