# Newbie question regarding drives, second phase

**URL:** <https://rubytalk.org/t/newbie-question-regarding-drives-second-phase/5212>\
**Category:** ruby-talk\
**Created:** [18 March 2003 16:12 UTC](https://rubytalk.org/t/newbie-question-regarding-drives-second-phase/5212 "2003-03-18T16:12:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sperberg\_Roger](https://avatars.discourse-cdn.com/v4/letter/s/ea5d25/32.png) [@Sperberg\_Roger](https://rubytalk.org/u/Sperberg_Roger)\
**Post date:** [18 March 2003 16:12 UTC](https://rubytalk.org/t/newbie-question-regarding-drives-second-phase/5212/1 "2003-03-18T16:12:08Z")

</div>

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](mailto:roger.sperberg@aspenpubl.com)

> **···**
>
> > -----Original Message-----  
> > From: Chris Morris [[mailto:chrismo@clabs.org](mailto:chrismo@clabs.org)]  
> > Sent: Wednesday, March 05, 2003 1:30 PM  
> > To: [ruby-talk@ruby-lang.org](mailto: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](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” [roger.sperberg@aspenpublishers.com](mailto:roger.sperberg@aspenpublishers.com)  
> > To: “ruby-talk ML” [ruby-talk@ruby-lang.org](mailto:ruby-talk@ruby-lang.org)  
> > 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

---

<div class="post-metadata">

**Author:** ![Chris\_Morris](https://avatars.discourse-cdn.com/v4/letter/c/6de8d8/32.png) [@Chris\_Morris](https://rubytalk.org/u/Chris_Morris)\
**Post date:** [18 March 2003 18:29 UTC](https://rubytalk.org/t/newbie-question-regarding-drives-second-phase/5212/2 "2003-03-18T18:29:22Z")

</div>

> However, to my way of thinking, calling it directly from Windows would be  
> more efficient.

More efficient for the machine (though not noticeably), terribly inefficient  
for you 🙂 The Windows API is pretty low-level. I do little directly with  
the API if I can help it. Everyone uses libraries that sit on top of the  
API – C++ has MFC, Delphi has the VCL, VB is, well, VB, Java uses the  
Virtual Machine for Windows which handles all the API talking, etc etc.

Back to your problem – will your Flash be served from a web server, or  
somehow run locally? Also, what sort of access do you need to the client  
drive? If you’re coming from a web server, you will have very definite  
limitations of what client-side things you can access. There is one caveat I  
know of, and that is a certain CGI form element that should kick open a  
dialog for the user to select a file for uploading to the server, or some  
such – I’m a bit hazy on that.

Chris
