Hi there
I need to get substed drive letter in Perl. Could anyone kindly help me? $ENV{SYSTEMDRIVE} does not work; it gives me real logical drive letter, not the substed one.
thanxalot for your help
Hi there
I need to get substed drive letter in Perl. Could anyone kindly help me? $ENV{SYSTEMDRIVE} does not work; it gives me real logical drive letter, not the substed one.
thanxalot for your help
If you want to do it yourself, you could capture the output of the subst command and process it, since it outputs all current substituted drives.
SUBST [drive1: [drive2:]path]
SUBST drive1: /D
drive1: Specifies a virtual drive to which you want to assign a path.
[drive2:]path Specifies a physical drive and path you want to assign to
a virtual drive.
/D Deletes a substituted (virtual) drive.
Type SUBST with no parameters to display a list of current virtual drives.
C:\Documents and Settings\Administrator\My Documents>subst r: c:\bin
C:\Documents and Settings\Administrator\My Documents>subst
R:\: => C:\bin
In order to do this, you need a function to return the subst'ed output, as follows:
sub get_drive {
my $drv = shift;
my $ln;
$drv = substr($drv,0,1);
open (IN, "subst |");
while ($ln = <IN>) {
chomp ($ln);
if ((substr($ln,0,1) eq $drv) && (substr($ln,1,6) eq ":\\: =>")) {
close (IN);
return substr($ln,8);
}
}
close (IN);
return $drv . ":\\";
}
print get_drive ("R:") . "\n";
print get_drive ("S:") . "\n";
This outputs:
C:\bin
S:\
on my system which has only the one subst'ed drive.
thanks to all, at last I solved it by much easier way - by using getcwd command to get current working directory and then I used first two letters from its output - so simple:-)
use Cwd;
my $driveletter = substr(getcwd, 0, 2);