From: Heesob Park Date: 2008-04-30T11:44:59+09:00 Subject: Re: How can I suppress popups on Windows during File.exists? 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-forum.com/.