How to overwrite existing files in batch?

半城伤御伤魂 提交于 2019-12-03 02:29:13

问题


The following command copies and moves a file but I also need it to overwrite the file it's replacing.

xcopy /s c:\mmyinbox\test.doc C:\myoutbox

回答1:


Add /Y to the command line




回答2:


You can use :

copy /b/v/y

See SS64 on COPY.




回答3:


Add /y to the command line of xcopy:

Example:

xcopy /y c:\mmyinbox\test.doc C:\myoutbox



回答4:


you need to simply add /Y

xcopy /s c:\mmyinbox\test.doc C:\myoutbox /Y

and if you're using path with spaces, try this

xcopy /s "c:\mmyinbox\test.doc" "C:\myoutbox" /Y



回答5:


If the copy command is run from within a batch job you do not need to use the /Y switch: it will overwrite existing files.




回答6:


You can refer Windows command prompt help using following command : xcopy /?




回答7:


If destination file is read only use /y/r

xcopy /y/r source.txt dest.txt



回答8:


A command that would copy in any case

xcopy "path\source" "path\destination" /s/h/e/k/f/c/y


来源:https://stackoverflow.com/questions/4051294/how-to-overwrite-existing-files-in-batch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!