Violet Giraffe
Violet Giraffe

Reputation: 33579

xcopy doesn't work with relative path and environment variable

I'm executing the following command:

xcopy /Y /R "%VS140COMNTOOLS%..\IDE\CommonExtensions\Platform\DiagnosticsHub\x86\dbghelp.dll" binaries\msvcr\

This command results in the following:

File not found - dbghelp.dll
0 File(s) copied

echo %VS140COMNTOOLS% yields the following - I merely expanded the environment variable:

C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\

Meanwhile, the following command works:

 xcopy /R /Y "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\..\IDE\CommonExtensions\Platform\DiagnosticsHub\x86\dbghelp.dll" binaries\msvcr\

C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\..\IDE\CommonExtensions\Platform\DiagnosticsHub\x86\dbghelp.dll
1 File(s) copied

What's the problem?

Upvotes: 2

Views: 4641

Answers (1)

Mofi
Mofi

Reputation: 49086

xcopy /Y /R "%VS140COMNTOOLS%..\IDE\CommonExtensions\Platform\DiagnosticsHub\x86\dbghelp.dll" binaries\msvcr\

The command line above fails with the error message below in 4 cases:

File not found - dbghelp.dll
0 File(s) copied

  1. The folder path assigned to environment variable VS140COMNTOOLS does not end with a backslash.
    This possible cause of error is obviously not the case here as echo %VS140COMNTOOLS% prints the folder path with a backslash at end.

  2. The environment variable has the string value:
    %ProgramFiles(x86)%\Microsoft Visual Studio 14.0\Common7\Tools\
    But this is not the case here as otherwise echo %VS140COMNTOOLS% would print that string.

  3. The folder path assigned to environment variable VS140COMNTOOLS has 1 or more trailing spaces/tabs.

  4. The folder path assigned to environment variable VS140COMNTOOLS starts with 1 or more leading spaces/tabs.

For the second and third cause of error it would help to run echo "%VS140COMNTOOLS%" and look if the output is:

"C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\ "

or

" C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\"

Using syntax set variable=value can easily result in getting the value with trailing spaces/tabs assigned to the environment variable resulting on usage in errors like this one. The solution is using set "variable=value" as explained in detail in answer on Why is no string output with 'echo %var%' after using 'set var = text' on command line?

For completeness a definition of the environment variable VS140COMNTOOLS with the command line

set VS140COMNTOOLS="C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\"

with first double quote after equal sign instead of left to variable name and no trailing spaces/tabs would result in execution the command line:

xcopy /Y /R ""C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\"..\IDE\CommonExtensions\Platform\DiagnosticsHub\x86\dbghelp.dll" binaries\msvcr\

But this command line would result in the error message:

Invalid number of parameters

So already double quoted folder path can be also excluded as possible cause of the error.

BTW: The help of xcopy output by running in a command prompt window xcopy /? lists the optional parameters after source and target parameters. It is of course possible to specify first /R /Y and then source file and target folder, but it is in general advisable to use the syntax as suggested by help of command.

Upvotes: 1

Related Questions