# How to read drive label

**URL:** <https://www.ruby-forum.com/t/how-to-read-drive-label/149066>\
**Category:** Ruby\
**Created:** [September 19, 2008, 11:13pm UTC](https://www.ruby-forum.com/t/how-to-read-drive-label/149066 "2008-09-19T23:13:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tbaustert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ecae2f/32.png) [@tbaustert](https://www.ruby-forum.com/u/tbaustert)\
**Post date:** [September 19, 2008, 11:13pm UTC](https://www.ruby-forum.com/t/how-to-read-drive-label/149066/1 "2008-09-19T23:13:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![tbaustert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ecae2f/32.png) [@tbaustert](https://www.ruby-forum.com/u/tbaustert)\
**Post date:** [September 20, 2008, 12:19am UTC](https://www.ruby-forum.com/t/how-to-read-drive-label/149066/2 "2008-09-20T00:19:02Z")

</div>

Thomas B. wrote:

> 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
