Here is a very simple batch file called "copyTXT.bat", that I am trying to execute:

XCOPY /v D:\temp\MyFile.txt D:\Documents\

For some reason that I just cannot grasp, it fails. It flashes a window for 1/10 of a second and do nothing, no copy at all. If I call the batch file from a command window it will generate the following error message:

" X is not recognized as an internal or external command... "

Yet , If I run the command directly in the command window It will execute and perform as intended.
Some users happen to think that it could be a question of rights or a badly defined Path. I am using this in an Administrator account and I checked my Path environment which include the C:\Windows\System32 folder. I also copied the XCOPY.EXE file right into the D:\temp folder, just to make sure. I am executing the batch file from the D:\temp folder and this is also the location of the batch file itself. Furthermore, I can run the same exact batch file on another computer running the same windows 7 OS.

What am I doing wrong ? How come the batch file fail and yet I can execute the command directly with no problem ?

  • 2
    Try doing a new batch file with the same command (run the command in CMD and then copy it from there and paste it in the batch file. (I suspect that there's some invisible character there in the batch file.) – Yisroel Tech Feb 23 '17 at 3:20
  • Your command is valid on Windows 7. As suggested it's likely there's something wrong with your .BAT file. – Twisty Impersonator Feb 23 '17 at 21:28
  • How did you make the batch file, exactly? Could you upload it e.g. on ge.tt? Did the error message say X is not recognized etc. instead of XCOPY? I tried replicating the issue by putting one LF character (thus omitting the CR) between X and COPY. Editors like Notepad would show everything on one line, which can be copy-pasted on the command prompt, running just fine. Starting the .bat would give a X is not recognized error and the COPY command would run instead. By saving as UTF-8 with BOM the batch would return ╗┐XCOPY is not etc. Not quite like yours, still. – and31415 Feb 24 '17 at 22:06

There's probably a ZWS (Invisible character) between the X and the COPY just rewrite the command yourself without any ZWS that would probably fix it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.