4

D:\temp\copyTXT.bat is a simple script containing:

XCOPY /v D:\temp\MyFile.txt D:\Documents\
  • Executing the script fails, flashing a window for ~100ms, then does nothing (no copy at all), but if I call the batch file from a terminal, it errors with:
    X is not recognized as an internal or external command...
    
  • If I run the command itself from a terminal, it performs as intended

Some think it could be a question of rights or a badly defined path:

  • I am using an Administrator account and verified %PATH% includes C:\Windows\System32
  • I've copied XCOPY.exe to D:\temp\ to make sure, and am executing the batch file from within D:\temp
  • I can run the same exact batch file on another computer running the same Windows 7 OS

What am I doing wrong? Why does the batch file fail, yet I can execute the command directly with no problem?

3
  • 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.) Commented Feb 23, 2017 at 3:20
  • Your command is valid on Windows 7. As suggested it's likely there's something wrong with your .BAT file. Commented Feb 23, 2017 at 21:28
  • 1
    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
    Commented Feb 24, 2017 at 22:06

1 Answer 1

0

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .