I have this code:
FOR %%d IN (c d e f g h i j k l m n o p q r s t u v w x y z) do (
IF NOT EXIST %%d:\ (
echo Free drive %%d
set D=%%d:
)
)
echo d=%D%
echo Using %D% to map remote drive
subst %D% /d
subst %D% \\path_to_drive
and after this I'm using the D
variable to map a free drive. The thing is, when I first run this, and try to map the drive, the script thinks that the D variable is undefined, or contains nothing. If I print it's value when the script ends, with:
set D
I see that it found a drive, and it got it's value. When I run the script a second time, it will work as expected. It drives me crazy that batch thinks the variable is undefined, and after the script finishes it's execution it has a value. I'd also like to add that this is the only part where the D
variable is used, and that there will ALWAYS
be at least one free drive, so, the fact that no drives are available isn't true.
EDIT: I've added the lines that I use to map the drive.