# How can I suppress popups on Windows during File.exists?

**URL:** <https://www.ruby-forum.com/t/how-can-i-suppress-popups-on-windows-during-file-exists/136220>\
**Category:** Ruby\
**Created:** [April 29, 2008, 10:36pm UTC](https://www.ruby-forum.com/t/how-can-i-suppress-popups-on-windows-during-file-exists/136220 "2008-04-29T22:36:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Landon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/a88e57/32.png) [@Landon](https://www.ruby-forum.com/u/Landon)\
**Post date:** [April 29, 2008, 10:36pm UTC](https://www.ruby-forum.com/t/how-can-i-suppress-popups-on-windows-during-file-exists/136220/1 "2008-04-29T22:36:06Z")

</div>

I apologize if this is a double post - I subscribed through the ruby-  
lang web page, but didn’t get any email back, then sent mail to  
subscribe the manual way…same thing - no confirmation of response -  
then I emailed the post.

First, the real problem I’m trying to solve is the enumeration of all  
the valid drives on a Windows machine without ending up with windows  
popups flying.

Related to this objective, I need to do it in a way which is is most  
compatible with both pure ruby and JRuby in a single code base.  
Finally, this ruby code cannot be interactive or create an interactive  
situation…it has to run unattended.

What I’m finding is that on different windows machines, I’ll get  
various kinds of popups depending upon whether the drive doesn’t exist  
or has no media in it.

For example, on a windows machine with no floppy in the drive, if I go  
to irb and type:

> File.exists?(“a:”)

I will get a Windows popup that has the title:

Windows - No Disk

The contents of the popup says: "Exception Processing Message  
c0000013 Parameters 75b6bf9c 4 75b6bf9c 75b6bf9c

If I cancel the popup, it comes back once more. If I cancel it a 2nd  
time, it finally returns to Ruby and the irb prompt.

Second variation on the problem is if I try to access something on the  
CD-ROM assigned to D: but there is nothing in the D: drive. Again,  
in irb, if I type:

> File.exists?(“d:”)

I will get a different kind of popup. This one’s title says "ruby.exe

- No Disk" and the contents say “There is no disk in the drive. Please  
insert a disk into drive D:”

If I put a begin/rescue around the File.exists? call, rescue is never  
executed, so no exception is being thrown.

So, several questions come out of these experiments:

1. Is there an alternate, standard way to enumerate drives on a  
windows machine using Ruby?
2. Is there a way to suppress these windows popups or alternatively  
have Ruby throw an exception in these cases?
3. any other ideas?

Any help on overcoming these issues in a standard, Ruby way would be  
very appreciated.

Thanks,

Landon

---

<div class="post-metadata">

**Author:** ![Landon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/a88e57/32.png) [@Landon](https://www.ruby-forum.com/u/Landon)\
**Post date:** [April 30, 2008, 4:44am UTC](https://www.ruby-forum.com/t/how-can-i-suppress-popups-on-windows-during-file-exists/136220/2 "2008-04-30T04:44:57Z")

</div>

Hi,  
Landon wrote:

> I apologize if this is a double post - I subscribed through the ruby-  
> lang web page, but didn’t get any email back, then sent mail to  
> subscribe the manual way…same thing - no confirmation of response -  
> then I emailed the post.
> 
> First, the real problem I’m trying to solve is the enumeration of all  
> the valid drives on a Windows machine without ending up with windows  
> popups flying.
> 
> Related to this objective, I need to do it in a way which is is most  
> compatible with both pure ruby and JRuby in a single code base.  
> Finally, this ruby code cannot be interactive or create an interactive  
> situation…it has to run unattended.
> 
> What I’m finding is that on different windows machines, I’ll get  
> various kinds of popups depending upon whether the drive doesn’t exist  
> or has no media in it.
> 
> For example, on a windows machine with no floppy in the drive, if I go  
> to irb and type:
> 
> > File.exists?(“a:”)
> 
> I will get a Windows popup that has the title:
> 
> Windows - No Disk
> 
> The contents of the popup says: "Exception Processing Message  
> c0000013 Parameters 75b6bf9c 4 75b6bf9c 75b6bf9c
> 
> If I cancel the popup, it comes back once more. If I cancel it a 2nd  
> time, it finally returns to Ruby and the irb prompt.
> 
> Second variation on the problem is if I try to access something on the  
> CD-ROM assigned to D: but there is nothing in the D: drive. Again,  
> in irb, if I type:
> 
> > File.exists?(“d:”)
> 
> I will get a different kind of popup. This one’s title says "ruby.exe
> 
> - No Disk" and the contents say “There is no disk in the drive. Please  
> insert a disk into drive D:”
> 
> If I put a begin/rescue around the File.exists? call, rescue is never  
> executed, so no exception is being thrown.
> 
> So, several questions come out of these experiments:
> 
> 1. Is there an alternate, standard way to enumerate drives on a  
> windows machine using Ruby?
> 2. Is there a way to suppress these windows popups or alternatively  
> have Ruby throw an exception in these cases?
> 3. any other ideas?
> 
> Any help on overcoming these issues in a standard, Ruby way would be  
> very appreciated.

Try with win32ole:

require ‘win32ole’

drive\_types = {  
0 =\> “Unknown type of drive”,  
1 =\> “Removable drive”,  
2 =\> “Fixed drive”,  
3 =\> “Network drive”,  
4 =\> “CD-ROM drive”,  
5 =\> “RAM Disk”  
}  
oFS = WIN32OLE.new(“Scripting.FileSystemObject”)  
oDrives = oFS.Drives  
oDrives.each() do |x|  
puts “drive:#{x.DriveLetter}, type:#{drive\_types[x.DriveType]},  
ready:#{x.IsReady}”  
end

Regards,

Park H.

---

<div class="post-metadata">

**Author:** ![Landon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/a88e57/32.png) [@Landon](https://www.ruby-forum.com/u/Landon)\
**Post date:** [May 1, 2008, 6:40pm UTC](https://www.ruby-forum.com/t/how-can-i-suppress-popups-on-windows-during-file-exists/136220/3 "2008-05-01T18:40:31Z")

</div>

Thanks for the info, Park. One of my requirements is that the solution  
be portable between Ruby and JRuby, which is why I was attempting to  
do drive detection with File.exists?

The JRuby guys have had implementing win32ole on their list for about  
a year: [http://jira.codehaus.org/browse/JRUBY-191](http://jira.codehaus.org/browse/JRUBY-191) but it hasn’t made  
its way up the priority list high enough to be addressed.

Anyway, thanks for the win32ole method of doing this - I’m sure that  
will come in handy.

On Apr 29, 8:44 pm, Heesob P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

Try with win32ole:

* * *

---

<div class="post-metadata">

**Author:** ![Landon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/a88e57/32.png) [@Landon](https://www.ruby-forum.com/u/Landon)\
**Post date:** [May 1, 2008, 10:58pm UTC](https://www.ruby-forum.com/t/how-can-i-suppress-popups-on-windows-during-file-exists/136220/4 "2008-05-01T22:58:36Z")

</div>

On Thu, May 1, 2008 at 11:40 AM, Landon [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On Apr 29, 8:44 pm, Heesob P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> Try with win32ole:
> 
> * * *

What versions of Windows and Ruby are you using. I don’t get this  
behavior with 1.8.6-p114 on Windows XP.

irb(main):003:0\> File.exists?(‘a:’)  
=\> false  
irb(main):004:0\> File.exists?(‘z:’) # cd-rom  
=\> false  
irb(main):005:0\> File.exists?(‘s:’) # network drive  
=\> true
