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.
Cheers,
V.-
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.
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.
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
Well, yes and no I was hoping to avoid Win32API but I’ll
settle for that now. Thanks,
I’m afraid, since drive letters are a misfeature specific to the
Win32 platform, that by definition you’re going to have problems
finding a platform-independent interface to it, elegant or
otherwise.
This task is accomplished with Perl using Win32::DriveInfo, which
in turn requires Win32::API. Likewise, this is served to Python
users via the win32api module.
Maybe if some more OSes appear that have the concept of drive
letters, and they gain a significant marketshare, we can offload
the Ruby interface to a ‘Drives’ module that internally
dispatches to Win32API, XsysAPI, YsysAPI, etc.; but I don’t
expect it to be added to the Kernel namespace anytime soon.
Cheers,
Tim Hammerquist
···
–
To accuse others for one’s own misfortunes is a sign of want of education.
To accuse onself shows that one’s education has begun.
To accuse neither oneself nor others shows that one’s education is complete.
– Epictetus
Well, yes and no I was hoping to avoid Win32API but I’ll
settle for that now. Thanks,
I’m afraid, since drive letters are a misfeature specific to the
Win32 platform, that by definition you’re going to have problems
finding a platform-independent interface to it, elegant or
otherwise.
This task is accomplished with Perl using Win32::DriveInfo, which
in turn requires Win32::API. Likewise, this is served to Python
users via the win32api module.
Maybe if some more OSes appear that have the concept of drive
letters, and they gain a significant marketshare, we can offload
the Ruby interface to a ‘Drives’ module that internally
dispatches to Win32API, XsysAPI, YsysAPI, etc.; but I don’t
expect it to be added to the Kernel namespace anytime soon.
Cheers,
Tim Hammerquist
I wouldn’t dream of even daring to utter that the possibility had
crossed my mind. It took me about half an hour to write my own module to
get the drives. I was trying to avoid wading through the MSDN
documentation to find the right calls - being lazy as always.
Anyway, this kind of cruft gets on my nerves, trying to accomplish
anything in Windows is always a drag :(.
V.-