How to read drive label

T

Thomas B.

Hello. I'd like to get the labels of the hard drives (partitions) on my
machine from within a program. Is there any universal Ruby command to do
it?

I'm on Windows, so I guess I could use some WinAPI to do that but I'd
prefer not to, if it is possible. But any solution will be appreciated!

TPR.
 
S

Siep Korteling

Thomas said:
Hello. I'd like to get the labels of the hard drives (partitions) on my
machine from within a program. Is there any universal Ruby command to do
it?

I'm on Windows, so I guess I could use some WinAPI to do that but I'd
prefer not to, if it is possible. But any solution will be appreciated!

TPR.

For windows:

require 'ruby-wmi'

disks = WMI::Win32_LogicalDisk.find:)all, :conditions=>{:drivetype=>3})

disks.each do |disk|
puts "#{disk.deviceid} #{disk.volumename}"
end

# There is a lot more info in "disks"
puts "_______________________"

disks.each do |disk|
disk.properties_.each do |p|
puts "#{p.name}: #{disk[p.name]}" unless (disk[p.name]).nil?
end
end


hth,

Siep
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,201
Messages
2,571,048
Members
47,651
Latest member
VeraPiw932

Latest Threads

Top