Windows copy command return codes?

前端 未结 5 517
[愿得一人]
[愿得一人] 2020-12-15 16:43

I would like to test for the success/failure of a copy in a batch file, but I can\'t find any documentation on what if any errorlevel codes are returned. For example

<
5条回答
  •  鱼传尺愫
    2020-12-15 17:22

    It might also be worth pointing out that xcopy doesn't always return the error code you expect.

    For example when trying to copy multiple files with a wildcard but there are no files to copy you expect a return error code of 1 ("No files were found to copy"), but it actually returns 0 ("Files were copied without error")

    C:\Users\wilson>mkdir bla
    
    C:\Users\wilson>mkdir blert
    
    C:\Users\wilson>xcopy bla\* blert\
    0 File(s) copied
    
    C:\Users\wilson>echo %ERRORLEVEL%
    0
    

提交回复
热议问题