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

I need to be able to determine if a drive is a mapped network drive or a local drive on a win32 machine. Say the path given is "h:\some\path", is there a way to test for the drive's "networkness" using perl? The win32 GUI knows and displays the appropriate network drive icon, but I can't seem to find a CLI based equivalent for this info.

I've searched CPAN looking for some administrator functionality that may address this issue, but I didn't find anything pertinent.

Thanks, beta
  • Comment on Determine if a win32 drive is mapped or local

Replies are listed 'Best First'.
(tye)Re: Determine if a win32 drive is mapped or local
by tye (Sage) on Nov 29, 2001 at 02:43 UTC

    use strict; use Win32API::File qw( :DRIVE_ GetDriveType ); my $drive= "Y:"; my $type= GetDriveType($drive); if( DRIVE_REMOTE == $type ) { warn "Drive $drive is remote.\n"; } elsif( DRIVE_FIXED == $type ) { warn "Drive $drive is local harddisk.\n"; } elsif( DRIVE_CDROM == $type ) { warn "Drive $drive is local CD-ROM.\n"; } elsif( DRIVE_REMOVABLE == $type ) { warn "Drive $drive is local but media my not be present.\n"; } elsif( DRIVE_RAMDISK == $type ) { warn "Drive $drive is memory-resident virtual.\n"; } else { warn "Drive $drive is probably invalid.\n"; }
    so DRIVE_FIXED or DRIVE_RAMDISK means you should have no problem accessing it. Other types might fail or take a while. Lots of other goodies in Win32API::File (for example, if you want to see if there is any media in drive) which comes standard with modern Perls.

            - tye (but my friends call me "Tye")