Reputation: 365
I have a batch script that checks to see if a directory exists then maps it, if it does exist.
if exist \\server\folder1\%username% net use g: \\server\folder1\%username%
Lately the script hasn't been mapping correctly with some computers, on those computers in needs to be change to
if exist \\server\folder1\%username%\ net use g: \\server\folder1\%username%
Why would that backslash make a difference? Isn't it pointing to the same directory? Why would "if exist" need it and "net use" not need it? Users do NOT have access to folder1.
Now, I came across an older version of the same file written by a previous employee and he wrote it as
net use g: \\\\server\folder1\%USERNAME%
Why would he put four slashes?
Upvotes: 1
Views: 962
Reputation: 130819
I'm not sure if this is your problem, but if exist \\server\folder1\%username%
is TRUE if %username%
is a valid file or folder within folder1.
Adding a backslash at the end forces the condition to only be true if a folder exists.
Upvotes: 2