5

I'm programming a batch file and after a long amount of code, I have:

:d1copy
xcopy /Y "C:\Users\Joseph\Desktop\JOKO_Sync\*.*" "F:\JOKO_Sync\*.*" /s /e /V /D
pause

When I execute this, I get the error

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

Yet I copy and paste this same code into another batch file, and it works perfectly.

Any ideas?

Mofi
  • 46,139
  • 17
  • 80
  • 143
JSUPRA
  • 61
  • 1
  • 1
  • 4
  • Does your `Path` environment variable include `C:\Windows\System32`! – Am_I_Helpful Aug 26 '14 at 07:58
  • Thanks for the response. It does not. Can I put a line in that just says "C:\Windows\System32 !" to fix that error? – JSUPRA Aug 26 '14 at 08:05
  • @JSUPRA Yes, you can do that, just don't forget the smicolon before – Radu Gheorghiu Aug 26 '14 at 08:07
  • Thanks. I haven't needed to do that before. So if I understand, it would be: :d1copy C:\Windows\System32! xcopy /Y "C:\Users\Joseph\Desktop\JOKO_Sync\*.*" "F:\JOKO_Sync\*.*" /s /e /V /D pause – JSUPRA Aug 26 '14 at 08:08
  • @JSUPRA-No,those are the contents of batch file, you should simply add the path of system32 in your Path environment variable – Am_I_Helpful Aug 26 '14 at 08:10
  • 4
    `set Path=%path%;C:\Windows\system32` this command will add C:\Windows\system32 folder to the `%path%` then xcopy will work – Badradish Aug 26 '14 at 08:10
  • 2
    If the same code work inside another batch file, the problem is the batch file, not the xcopy command. Are you using/changing the `path` variable inside this batch? – MC ND Aug 26 '14 at 08:29
  • MC ND's question is the likely reason for it failing. Just repeating here that you are probably using a variable called `path` – foxidrive Aug 26 '14 at 11:55

4 Answers4

18

Your Path environment variable doesn't contain C:\Windows\System32. Please try adding it and your error will be resolved!

Am_I_Helpful
  • 18,735
  • 7
  • 49
  • 73
  • Thanks for the advice. This is what I'm running now: :d1copy xcopy /Y "C:\Windows\System32\Users\Joseph\Desktop\JOKO_Sync\*.*" "F:\JOKO_Sync\*.*" /s /e /V /D pause Unfortunately I'm still getting the same error – JSUPRA Aug 26 '14 at 08:13
  • Did you add `System32` location into `Path` as it contains all the executables. – Am_I_Helpful Aug 26 '14 at 08:15
  • No I haven't. Do you write a line of code to do that? – JSUPRA Aug 26 '14 at 08:17
  • My file path on x copy now reads "C:\Windows\System32\Users\Joseph\Desktop\JOKO_Sync\*.*" But it's not working, so Im guessing I need to add System32 to the path in a different way – JSUPRA Aug 26 '14 at 08:20
  • Whatever contents are right now added to your `Path` variable,you just leave it unchanged! Just append `C:\Windows\System32` this to the end if there is a semi-colon`(;)` at the end! If it ain't, then append this--->`;C:\Windows\System32\`. Please don't delete the contents! SImply append at last.... – Am_I_Helpful Aug 26 '14 at 08:20
  • Have you added upto `JOKO` in your Path environment variable??? If yes,don't!!! Please remove that! If not,then kindly add as hinted in the above comment... – Am_I_Helpful Aug 26 '14 at 08:22
  • Thanks for your continued help. Here is what I have tried: xcopy /Y "C:\Users\Joseph\Desktop\JOKO_Sync\C:\Windows\System32;" "F:\JOKO_Sync\*.*" /s /e /V /D xcopy /Y "C:\Users\Joseph\Desktop\JOKO_Sync\" "F:\JOKO_Sync\*.*" /s /e /V /D C:\Windows\System32; – JSUPRA Aug 26 '14 at 08:26
  • Has any of those lines I have posted come close to what you are talking about? – JSUPRA Aug 26 '14 at 08:29
  • probably not. why are you adding the system32 path to the file ypu want to copy, instead to xcopy? – ths Aug 26 '14 at 08:32
  • Got it. It's coming up with a different error now, so it solved the problem. Many thanks for your help. – JSUPRA Aug 26 '14 at 08:34
  • Well you really helped me out and I appreciate it. Thanks again – JSUPRA Aug 26 '14 at 08:38
  • @JSUPRA-Glad to help you. Good luck for your project! – Am_I_Helpful Aug 26 '14 at 08:39
2

Maybe you may have defined set path= to something in your batch file. So it'll change your current system path variable. If so change your batch file variable name different to "path" (ex: mypath) and it will work.

SparRow
  • 62
  • 5
  • three and a half year too late, but the first correct answer. By analyzing the comments, OP did in fact set `path` to his source folder – Stephan Jan 19 '18 at 11:43
1

Rather than setting the PATH variable (which could then still break if you moved the script to another machine), you could simply specify the full path to xcopy:

%systemroot%\System32\xcopy ...

so in your case:

%systemroot%\System32\xcopy /Y "C:\Users\Joseph\Desktop\JOKO_Sync\*.*" "F:\JOKO_Sync\*.*" /s /e /V /D
SharpC
  • 6,974
  • 4
  • 45
  • 40
0

Copying xcopy.exe file from C:/Windows/System32 to JAVA_SDK/bin worked for me.

activesince93
  • 1,716
  • 17
  • 37