From: Chris Morris Date: 2003-03-06T03:29:41+09:00 Subject: Re: Newbie question regarding drives 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" To: "ruby-talk ML" 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 >