Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check if drive exists

Status
Not open for further replies.

goliath

MIS
Aug 18, 1999
62
US
Hello,

I'm working on optimizing a login script (it's running too slow...)

I'm wondering if anyone has any idea's of a better way to handle my drive mapping routine.

Due to the fact that we're converting this to an executeable I'm trying to avoid adding modules. I'm thinking that there is a better way to check to see if a drive letter is already mapped / in use.

Thanks in advance!

# Drive Mapping Subroutine
sub DrvMap
{
print "Mapping: $drive: \\\\$server\\$share\n";
$drivechk = "$drive:\\"; # Set for drive letter check
if (chdir $drivechk) { # See if drive is in use
chdir("c:/") || die "cannot cd to c:/ ($!)";
if ($p == 1) {
print " * $drive: Already Exists, Removing!!!\n";
print " * ";
system("Net use $drive: /delete");
} else {
system("Net use $drive: /delete>>nul"); # silent
}
}
my($drive,$server,$share) =@_;
if ($p == 1) {
print " ";
system("Net use $drive: \\\\$server\\$share /persistent:NO");
} else {
system("Net use $drive: \\\\$server\\$share /persistent:NO>>nul"); # silent
}
}
 
No reply's? I must be doing it right then? =)

I'm still researching but it seems to me that there must be a better way to check if a drive exists / is mapped than:

$drive = d
$drivechk = "$drive:\\"; # drive letter to check
if (chdir $drivechk)

Thanks in advance for any tips!
 
I don't play in the win world much, so there is probably a better way. Anyway, here is one very brief example of using the Win32API module. The 'getLogicalDrives' function may not be exactly what you are looking for.
Take a look at "perldoc Win32API::File".
Code:
#!perl
use strict;
use Win32API::File 0.08 qw( :ALL );
my @drives = getLogicalDrives();
foreach (@drives) { print "DRIVE: $_\n"; }

or, you might just use
Code:
#!perl
if (-d "c:\\") { print "File exists.\n"; }
'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
Yes, Thank you for:
if (-d "c:\\") { print "File exists.\n"; }

Thats exactly what I was looking for =)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top