From: "Sperberg, Roger" Date: 2003-03-19T01:12:08+09:00 Subject: Re: Newbie question regarding drives, second phase Chris, I thanked you before for your help with this issue. I downloaded your software and got my program to do what I wanted it to. I've taken a step back from the problem, however, and maybe I was asking the wrong question. I'm writing to ask you for one more piece of help. So, in order to ask it, let me explain. I've been using Flash as a frontend for the simple Ruby programs I write -- I already understand Flash and I figure it's best to understand as much as possible of what I'm doing, and RubyTK and FXRuby both present problems for me in terms of understanding an alien logic. So Flash is fine, except that owing to its web antecedents there is no built-in way to access the contents of a computer's local drive(s). There's no simple method for calling up an Open dialog box like every reasonable GUI language has. I have these alternatives, I reason: I can create such a dialog in FLash (hence my start with finding out what drives a computer has); I can include Fox or TK and just use the part that calls the Open dialog box; I can call it from Win32API. In the long run, I expect I'll benefit from completing variation 1. But in order to learn Ruby and put my simple programs in a GUI I'm spending all my time right now working in Flash's version of Javascript, called Actionscript. Being a very beginning programmer, I think I had better stick to one language at a time. My first efforts I actually went ahead and created with FXRuby; however, these programs fail my principle of Understand What You Write. (One of the reasons I like Ruby so much.) So I am thinking that I should just use a blackbox approach to the issue of getting an open dialog onscreen -- use Flash for my GUI and stick in a line that calls that dialog. I can put in the appropriate line for FXRuby that will do that. However, to my way of thinking, calling it directly from Windows would be more efficient. The half-hour or so I've perused the MSDN documentation about Windows gives me the shudders (did I mention I come from a tech-writing background, and that I use Ruby for string manipulations? In other words: an English major). So, to my question: if I were to use Win32API to get an open dialog box, do you know what the line should say? Or: do you know where there are some examples that I could study and imitate? Or: do you have an idea the best way to figure this out or the best place to ask? Thanking you in advance for you guidance, and your patience with me as I wobbled my way to asking for help. Yours, Roger Sperberg roger.sperberg@aspenpubl.com > -----Original Message----- > From: Chris Morris [mailto:chrismo@clabs.org] > Sent: Wednesday, March 05, 2003 1:30 PM > To: ruby-talk@ruby-lang.org > 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 > > > >