tart has asked for the wisdom of the Perl Monks concerning the following question:

Hi All, In my script I am trying to locate a file in windows drive.
As file could be in any drive so I am looping each letter such as,

foreach my $drive("a".."z") { if(-e "$drive:\\appcmd.exe") {

When 'a:' drive dose not exists in Windows or its floppy
drive and not accessible windows complains by sending warning message,

Windows - No Disk
Exception Processing Message c0000013 Parameters 75b6bf7c 4 75b6bf7c 75b6b7c


Can Any one suggest me better way to do this check? You
might suggest that I should use Win32::DriveInfo but for
some technical difficulties I can can not use it.

Please suggest if you have any ideas.Thanks,

Regards, tart

Replies are listed 'Best First'.
Re: Checking Windiows Drive exception.
by Corion (Patriarch) on Feb 03, 2012 at 07:48 UTC

    I use the following code to suppress "Media not inserted" messageboxes:

    BEGIN { if ($^O =~ /\bMSWin32\b|\bcygwin\b/) { require Win32::API; Win32::API->import(); Win32::API->Import('kernel32', 'SetErrorMode', 'I', 'I'); my $errormode = SetErrorMode(1); # fetch old error mode SetErrorMode(1 | $errormode); # no AbortRetryFail messages any +more }; };

    Your code has two serious bugs in it already. First, you are not using strict.pm, which is why your typo of $drive and $dive will go unnoticed by Perl. Second, you are using backslashes in a double quoted string. \a in a double-quoted string means the "bell" character. Please see perlop on quotes.

Re: Checking Windiows Drive exception.
by Anonymous Monk on Feb 03, 2012 at 07:52 UTC
Re: Checking Windiows Drive exception.
by rovf (Priest) on Feb 03, 2012 at 12:31 UTC
    I'm not a Windows expert, so I used a pretty naive solution in my environment: Issuing a net use command and parsing the output. Maybe not the most elegant and efficient solution, but so far it works for me....

    (Of course, if someone knows good reason why my approach might break, please let me know).

    -- 
    Ronald Fischer <ynnor@mm.st>
Re: Checking Windiows Drive exception.
by Marshall (Canon) on Feb 03, 2012 at 20:15 UTC
      Thanks Marshell, vol command is what I need!