From: Bill Kelly Date: 2003-07-26T08:15:28+09:00 Subject: Re: Quick way to find all drives in a windows box Hi, From: "Damphyr" > > 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 one way: # define the call: >> require 'Win32API' => true >> GetLogicalDriveStrings = Win32API.new("kernel32", "GetLogicalDriveStrings", ['L', 'P'], 'L') => # # create a buffer to hold the result and execute the call: >> buf = "\0" * 1024 >> len = GetLogicalDriveStrings.call(buf.length, buf) => 40 # if successful, is now the length of the null-terminated # drive names appended into the buffer.... (if failed, will # be zero, or some size exceeding the length we passed in) # looking at the raw data... >> buf[0..len] => "A:\\\000C:\\\000D:\\\000E:\\\000F:\\\000G:\\\000M:\\\000P:\\\000T:\\\000Z:\\\000\000" # split drive strings into array: >> buf[0..len].split("\0") => ["A:\\", "C:\\", "D:\\", "E:\\", "F:\\", "G:\\", "M:\\", "P:\\", "T:\\", "Z:\\"] Hope this helps, Bill