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

8

35

I have a problem using 'xcopy' command.

I'm building a C# project with msbuild. At the end of the build, a batch file is called to copy my assemblies from Debug/Release to some other folders.

Here is the problem, my build fail and the error log is 'xcopy is not recognized as an internal or external command, operable program or batch file'.

The path is correctly set, xcopy do works from a windows command line and from the visual studio command line (the one set with the project environment).

I tried to set the path in the batch file but it doesn't help.

Any suggestion?

I'm using windows 7

Cheers :)

Reyreyes answered 24/6, 2013 at 10:37 Comment(0)
R
45

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.

Rectocele answered 16/7, 2013 at 14:23 Comment(0)
R
18

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

Retaliation answered 3/12, 2013 at 10:21 Comment(1)
Setting Powershell path will overwrite Xcopy path. So powershell command will be executed but XCopy command will give error. I need a solution where both worksBeefy
L
14

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.

Linger answered 16/1, 2014 at 10:54 Comment(2)
Spot on Phil! In my case this was on Windows XP and the entry in the registry (HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment\Path) had indeed been set to a REG_SZ. Re-establishing the path from Control Panel > System > Advanced > Environment Variables corrected it in the registry. When I started a new command prompt, the path was properly "expanded".Brewery
So glad I found this answer! That was exactly the problem on my machine.Harvester
S
6

It happened to me after I updated one of my Visual Studio extensions, during which Visual Studio was closed and reopened by the updater. I could no longer properly build my project. I closed Visual Studio and reopened it and the problem went away.

Stableman answered 30/12, 2013 at 19:28 Comment(1)
Same here. Closing VS and opening it again solved the problem.Baumann
F
1

I also had a problem with xcopy (same error message) - with a very simple batch program that I use to backup files to a removable drive. Have been using that program for at least 5 years with never a problem. Then yesterday xcopy is unknown to Win7. The replacement of xcopy with %systemroot%\System32\xcopy at each instance solved the problem. Very strange.

Fourgon answered 15/11, 2013 at 2:4 Comment(0)
S
1

I just experienced this for the first time with a batch file I use to copy an Access front-end app to the user's local machines. Their environment is a mix of Windows 7 & 8 and 32-64 bit machines. I noticed that the xcopy.exe was both in the System32 and the SysWOW64 folders and I wondered if there was some conflict. So -- I copied the xcopy.exe into the folder where the batch file resides and it now seems to be working. Just thought I'd share this.

Eileen

Sour answered 13/4, 2015 at 21:45 Comment(0)
B
0

Go to environment variable and correct PATh including ; in last. It will work, this is not at all related to OS or Technology. It's working for me, Not even need to restart OS, Just open new command prompt.

Bindery answered 28/4, 2014 at 10:39 Comment(0)
A
0

[Fixed for me] After adding the correct paths to "Path" environmental variable it still doesn't work (for cmd and VisualStudio) (even after restarting the PC).

The problem was in broken register parameter: [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment] ParameterName=PATHEXT

I had the value .wlua;.|exe. Maybe was broken after installing something. Everything works again after changing it to: .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC

Hope this helps if nothing other works.

Altamira answered 25/1, 2019 at 10:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.