让 XCopy 复制文件并且不覆盖前一个文件(如果存在)(不提示)
我正在向远程计算机发送命令,以便让它复制文件。 我希望复制该文件,但不覆盖以前的同名文件(如果存在)。 我还需要命令在没有任何提示的情况下运行(xcopy 喜欢提示我指定的目标名称是文件还是目录,它还会提示覆盖文件)。
I'm sending 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 exists).
I also need the command to run without any prompts (xcopy likes to prompt whether the target name I've specified is file or directory, and it will also prompt about overwriting a file).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
我使用
xcopy /d
得到了很好的结果。它将复制较新的文件,并且由于我们可以假设现有文件具有相同的时间戳,因此您将仅复制不存在的文件。
I have good results with
xcopy /d
.It will copy NEWER files, and since we can assume that existing files have same time-stamp, you will copy only files that don't exist.
以防万一其他人发现这个:
robocopy x:\sourcefolder Y:\destfolder /s /e /r:0 /z
比 xcopy 好得多,甚至在末尾提供一个表格,通知任何失败或跳过的文件。不提示不要覆盖。
just in case anyone else finds this:
robocopy x:\sourcefolder Y:\destfolder /s /e /r:0 /z
much better than xcopy, even gives you a table at the end informing of any failed or skipped files. Doesn't prompt to not overwrite.
嗯,有一定的补救措施!它帮助我在为我们的产品演示编写设置时节省了在 Win10 上的大量精力和时间。
只需尝试使用管道:
@ECHO N|COPY /-Y SourceFiles Destination
作为示例,我使用了这个一段代码,这样我就会有一个干净、温柔、安静、安全的副本!
显然,FooPath 是源,GooPath 是目的地。
享受!
(主要来源:https://ss64.com/nt/copy.html)
Well, there's a certain remedy! It has helped me with saving much of my effort and time on Win10 while writing a setup for our product demo.
Just try to use piping:
@ECHO N|COPY /-Y SourceFiles Destination
As an example I used this piece of code so that I would have a clean gentle quiet and safe copy!
where obviously FooPath is the source and GooPath is the destination.
Enjoy!
(main source: https://ss64.com/nt/copy.html)
据我所知,没有办法让它不被覆盖。但 /Y 会覆盖它。 /I 将摆脱 file/dict 提示。请参阅
xcopy /?
了解所有选项No way to make it NOT overwrite as far as I know. but /Y will make it overwrite. and /I will get rid of the file/dict prompt. See
xcopy /?
for all options您还可以使用替换命令。它有两种模式:添加不存在的文件或替换存在的文件。您想要以前的模式:
You can also use the replace command. It has two modes: to add files that don't exist there or replace files that do exist. You want the previous mode:
以下命令复制文件和文件夹,但不覆盖文件(如果已存在)。
Following command copy files and folder but not override file if already exist.
我必须复制并重命名文件,因此我收到有关创建文件或目录的提示。
这是我这样做的相当“hackish”的方式:
XCOPY 将使用“F”来指示它应该将目标创建为文件:
我还验证了此命令不会影响现有文件。 (你也应该:-)
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:
XCOPY will use the "F" to indicate it should create the target as a file:
I've also verified this command leaves existing files alone. (You should too :-)