xcopy is not recognized as an internal or external command, operable program or batch file

I encountered the same problem.

It seems to be a problem with the path environment variable within Visual Studio.

When I added a "path" statement to the beginning of my build event, it produced the following output:

PATH=

This seems to indicate that the path is empty within the VS build environment.

When I specify the full path to xcopy like this, the problem went away:

%systemroot%\System32\xcopy ...

I'm not sure what caused Visual Studio to lose it's path.


Set Environment variable PATH = %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\


This is not a problem with Windows 7 or 8. It's actually a problem with applications that update environment variables such as PATH. The PATH is stored in the Registry as an "Expandable string value" (REG_EXPAND_SZ), but a lot of applications write it back to the Registry as a "String Value" (REG_SZ). If your path contains anything like %SYSTEMROOT%, this will not be expanded into C:\Windows (or whatever yours is) if the path is stored in a REG_SZ.

The fix is simply to edit your path manually from the control panel. You need to make a change (eg add a ; to the end of the path) and then apply it. This will fix up your path in the Registry to be a REG_EXPAND_SZ. (Go to the System Control Panel and select Advanced System Settings. Edit the Path Environment variable in the lower box, and that should fix it.

You can tell whether your path is broken in this way by opening a command prompt and typing PATH. Your path will be listed. If you can see anything enclosed in % % then your path is not being expanded.

Tags:

Xcopy