Pergunta

Alguém pode me dizer como posso obter uma lista das unidades de disco disponíveis em Ruby?Estou criando um diálogo de arquivo aberto e preciso saber!Agradecemos antecipadamente, el.

Foi útil?

Solução

O artigo que Brian forneceu afirma corretamente o seguinte código:

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
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top