Newbie question regarding drives

Can someone advise me of how to find out within my Ruby program what drives
are on a system, and what type of drive (local hard drive, floppy, CD-ROM,
etc.) they are?

I’m working with a Win2000 system, but it might also be used by someone
running Linux.

TIA,

Roger Sperberg

IIRC, I don’t think there’s a handy cross-platform solution.

Here’s code from my clUtil lib to do this on Windows:

Copyright Chris Morris

BSD License. Full download and license available here:

http://clabs.org/scrpware.htm – look for

cLabs Ruby Utilities

module Windows
def Windows.drives(typeFilter=nil)
Drives::drives(typeFilter)
end

module Drives
GetDriveType = Win32API.new(“kernel32”, “GetDriveTypeA”, [‘P’], ‘L’)
GetLogicalDriveStrings = Win32API.new(“kernel32”,
“GetLogicalDriveStrings”, [‘L’, ‘P’], ‘L’)

DRIVE_UNKNOWN      = 0 # The drive type cannot be determined.
DRIVE_NO_ROOT_DIR  = 1 # The root path is invalid. For example, no

volume is mounted at the path.
DRIVE_REMOVABLE = 2 # The disk can be removed from the drive.
DRIVE_FIXED = 3 # The disk cannot be removed from the drive.
DRIVE_REMOTE = 4 # The drive is a remote (network) drive.
DRIVE_CDROM = 5 # The drive is a CD-ROM drive.
DRIVE_RAMDISK = 6 # The drive is a RAM disk.
DriveTypes = {
DRIVE_UNKNOWN => ‘Unknown’,
DRIVE_NO_ROOT_DIR => ‘Invalid’,
DRIVE_REMOVABLE => ‘Removable/Floppy’,
DRIVE_FIXED => ‘Fixed’,
DRIVE_REMOTE => ‘Network’,
DRIVE_CDROM => ‘CD’,
DRIVE_RAMDISK => ‘RAM’
}

Drive = Struct.new('Drive', :name, :type, :typedesc)

def Drives.drives(typeFilter=nil)
  driveNames = ' ' * 255
  GetLogicalDriveStrings.Call(255, driveNames)
  driveNames.strip!
  driveNames = driveNames.split("\000")
  drivesAry = []
  driveNames.each do |drv|
    type = GetDriveType.Call(drv)
    if (!typeFilter) || (type == typeFilter)
      drive = Drive.new(drv, type, DriveTypes[type])
      drivesAry << drive
    end
  end
  drivesAry
end

end
end

···

----- Original Message -----
From: “Sperberg, Roger” roger.sperberg@aspenpublishers.com
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Wednesday, March 05, 2003 12:22 PM
Subject: Newbie question regarding drives

Can someone advise me of how to find out within my Ruby program what
drives
are on a system, and what type of drive (local hard drive, floppy, CD-ROM,
etc.) they are?

I’m working with a Win2000 system, but it might also be used by someone
running Linux.

TIA,

Roger Sperberg

“Sperberg, Roger” roger.sperberg@aspenpublishers.com wrote in message
news:212ACF1963F6D511832F0002A53FA3740119CF09@nycnt02.aspenpubl.com

Can someone advise me of how to find out within my Ruby program what
drives
are on a system, and what type of drive (local hard drive, floppy, CD-ROM,
etc.) they are?

I’m working with a Win2000 system, but it might also be used by someone
running Linux.

Windows only, WIN32OLE can be used to access the WMI COM objects (Windows
Management Instrumentation). These provide a whole range of system
information and control tools - even remote booting. See Microsoft MSDN
documentation for details. A random google brings
http://cwashington.netreach.net/depo/default.asp?topic=wmifaq

Mikkel

And I wouldn’t expect to find one, given that Windows and Unix-like
platforms treat drives very differently. Unix (including Linux)
doesn’t even have a notion of “drives” in the sense that you mean it:
it provides a unified view of all available storage, wherein various
storage devices can be attached to the (virtual) filesystem at
arbitrary points. IMHO, this is very user-friendly–after all, why
should the user have to worry about which hard drive to use?
Storage is storage is storage. However, a side-effect of this design
is that if you do need to identify the storage devices, it takes
significantly more work than it does for Windows.

···

On 6 Mar 2003 at 3:29, Chris Morris wrote:

From: “Sperberg, Roger” roger.sperberg@aspenpublishers.com

Can someone advise me of how to find out within my Ruby program what
drives
are on a system, and what type of drive (local hard drive, floppy, CD-ROM,
etc.) they are?

I’m working with a Win2000 system, but it might also be used by someone
running Linux.

IIRC, I don’t think there’s a handy cross-platform solution.


Matt Gushee
Englewood, CO USA