windows XCOPY:在 BATCH 中不提示地全部覆盖

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/47031941/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 19:58:58  来源:igfitidea点击:

XCOPY: Overwrite all without prompt in BATCH

windowsbatch-filecmdxcopy

提问by FZs

I create a batch program, which is copying all files newer than the destination from "C:\Users\ADMIN\Desktop" to "D:\Backup". This code is good:

我创建了一个批处理程序,它将所有比目标更新的文件从“C:\Users\ADMIN\Desktop”复制到“D:\Backup”。这段代码很好:

xcopy "C:\Users\ADMIN\Desktop\*.*" "D:\Backup\" /K /D /H

But it asks every existing destination files: Overwrite file [Yes / No / All]?

但它询问每个现有的目标文件: Overwrite file [Yes / No / All]?

I want to OVERWRITE all existing destination files WITHOUT user intervention.

我想在没有用户干预的情况下覆盖所有现有的目标文件。

How can I solve this?

我该如何解决这个问题?

Thanks for your answers!

感谢您的回答!

回答by FZs

The solution is the /Yswitch:

解决办法是/Y切换:

xcopy "C:\Users\ADMIN\Desktop\*.*" "D:\Backup\" /K /D /H /Y

回答by user3029478

If you want to make overwriting without asking be the default in Command sessions, go to Environment Variables. Choose New, and create one called COPYCMD, and give it a value of /Y. Create a new CMD session to try it.

如果您想在不要求成为命令会话中的默认设置的情况下进行覆盖,请转到环境变量。选择 New,并创建一个名为 COPYCMD 的,并为其赋值 /Y。创建一个新的 CMD 会话来尝试它。