Having XCopy copy a file and not overwrite the previous one if it exists (without prompting)

前端 未结 7 1767
独厮守ぢ
独厮守ぢ 2021-01-01 11:50

I\'m sending a commands to a remote computer in order to have it copy a file. I want the file to be copied, but not to overwrite the previous file with the same name (if it

7条回答
  •  星月不相逢
    2021-01-01 12:33

    I had to copy AND rename files, so I got the prompt about creating a file or a directory.

    This is the, rather "hackish" way I did it:

    ECHO F | XCOPY /D "C:\install\dummy\dummy.pdf" "C:\Archive\fffc810e-f01a-47e8-a000-5903fc56f0ec.pdf"
    

    XCOPY will use the "F" to indicate it should create the target as a file:

    C:\install>ECHO F   | XCOPY /D "C:\install\dummy\dummy.html" "C:\Archive\aa77cd6e-1d19-4eb4-b2a8-3f8fe60daf00.html"
    Does C:\Archive\aa77cd6e-1d19-4eb4-b2a8-3f8fe60daf00.html specify a file name or directory name on the target
    (F = file, D = directory)? F
    C:\install\dummy\dummy.html
    1 File(s) copied
    

    I've also verified this command leaves existing files alone. (You should too :-)

提交回复
热议问题