in reply to Error with GetDRIVE() when using a mapped drive

I get a similiar error when checking my CD drive when there's no CD in it, perhaps you should check the drive's isReady property.

The below code works (for me) for fixed drives, available network shares, "ready" removable drives and gives "uninitialized" errors on "not-ready" removables - except for the DriveLetter, DriveType and isReady properties.

(BTW if called from the command line (I use DWIM perl), I get a "drive not ready" dialogue in the latter case. When called from Padre, the "uninitialized" comes directly)

use warnings; use strict; use Win32::OLE 'in'; my $fs = Win32::OLE->CreateObject('Scripting.FileSystemObject'); for ( in $fs->Drives ) { print "$_->{DriveLetter}:\n"; my $d = $fs->GetDrive( $_->DriveLetter ); for ( qw(DriveLetter DriveType IsReady FileSystem TotalSize FreeSpac +e AvailableSpace) ) { print "$_: $d->{$_}\n"; } }
Note that in must be imported explicitly.

Replies are listed 'Best First'.
Re^2: Error with GetDRIVE() when using a mapped drive
by Corion (Patriarch) on Nov 04, 2014 at 08:39 UTC
      Ah, that's probably what Padre does, then. Thanks ;)
        Aha!, Thanks a lot. I noticed too and I changed it. Here is the code
        #!perl use warnings; use strict; use Win32::OLE; my $fs = Win32::OLE->CreateObject('Scripting.FileSystemObject'); my $d = $fs->GetDrive('Y:') or die "GetDrive failed $!"; my $TotalSize = $d->{TotalSize}; my $FreeSpace = $d->{FreeSpace}; my $usedSpace = $d->{TotalSize} -= $d->{FreeSpace}; my $AvailableSpace = $d->{AvailableSpace} *=100; my $AvailUsed = $AvailableSpace /= $d->{TotalSize}; my $SpaceLeft = $d->{AvailableSpace} /= $AvailUsed; my $MappedDriveSpaceAvailable = $AvailUsed *= 100; print "em_result=$MappedDriveSpaceAvailable";

        Now, there are the errors

        GetDrive failed Bad file descriptor at E:\APPL\OEM\NetworkDriveCheck.pl line 9.