From: Chris Morris Date: 2003-07-26T09:27:59+09:00 Subject: Re: Quick way to find all drives in a windows box Damphyr wrote: > Does anyone have a quick and elegant :) way to find all available > drive letters on a windows box? > I'm thinking in terms of Java File.listRoots() functionality. Here's a routine I've got in my spare cl/util/win.rb file you can get here http://www.clabs.org/dl/clutil/ # BSD Licensed code 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 -- Chris http://clabs.org/blogki