[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

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

Landon

4/29/2008 8:35:00 PM

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
5 Answers

Heesob Park

4/30/2008 2:45:00 AM

0

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 Heesob
--
Posted via http://www.ruby-....

Landon

5/1/2008 4:39:00 PM

0

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... 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 Park <pha...@gmail.com> wrote:

Try with win32ole:

---



Gordon Thiesfeld

5/1/2008 8:57:00 PM

0

On Thu, May 1, 2008 at 11:40 AM, Landon <LandonJCox@gmail.com> wrote:
> 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... 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 Park <pha...@gmail.com> 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

smorgas

10/27/2009 12:43:00 PM

0

On Mon, 26 Oct 2009 18:28:05 -0700, Klaus Schadenfreude
<klausschadenfreude@yahoo.com> wrote:

>>Lincoln represeneted Northern Progressivism
>
>Lincoln was a Republican. The GOP. He's ours. You can't have him,
>slaver.

You don't have his political ideology, Tin-Hat.

smorgas

10/27/2009 12:43:00 PM

0

On Mon, 26 Oct 2009 18:28:34 -0700, Klaus Schadenfreude
<klausschadenfreude@yahoo.com> wrote:

>In talk.politics.guns smorgas@board.com wrote:
>
>>You either hate the Constitution as I define it
>
>What an INTERESTING statement I forged. [chuckle]