让 XCopy 复制文件并且不覆盖前一个文件(如果存在)(不提示)

发布于 2024-10-19 17:13:14 字数 116 浏览 4 评论 0原文

我正在向远程计算机发送命令,以便让它复制文件。 我希望复制该文件,但不覆盖以前的同名文件(如果存在)。 我还需要命令在没有任何提示的情况下运行(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

盛装女皇 2024-10-26 17:13:14

我使用 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.

柏拉图鍀咏恒 2024-10-26 17:13:14

以防万一其他人发现这个:
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.

逆流 2024-10-26 17:13:14

嗯,有一定的补救措施!它帮助我在为我们的产品演示编写设置时节省了在 Win10 上的大量精力和时间。

只需尝试使用管道:

@ECHO N|COPY /-Y SourceFiles Destination

作为示例,我使用了这个一段代码,这样我就会有一个干净、温柔、安静、安全的副本!

@FOR /D %%F in ("FooPath") DO @(
   @ECHO N|COPY /-Y ^"%%~npdxF\*.*^" ^"GooPath^" 3>NUL 2>NUL >NUL
)

显然,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!

@FOR /D %%F in ("FooPath") DO @(
   @ECHO N|COPY /-Y ^"%%~npdxF\*.*^" ^"GooPath^" 3>NUL 2>NUL >NUL
)

where obviously FooPath is the source and GooPath is the destination.

Enjoy!

(main source: https://ss64.com/nt/copy.html)

烟酉 2024-10-26 17:13:14

据我所知,没有办法让它不被覆盖。但 /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

望她远 2024-10-26 17:13:14

您还可以使用替换命令。它有两种模式:添加不存在的文件或替换存在的文件。您想要以前的模式:

replace <path1> <path2> /A

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:

replace <path1> <path2> /A
何其悲哀 2024-10-26 17:13:14

以下命令复制文件和文件夹,但不覆盖文件(如果已存在)。

xcopy "*.*" "C:\test\"  /s /y /d

Following command copy files and folder but not override file if already exist.

xcopy "*.*" "C:\test\"  /s /y /d
旧时浪漫 2024-10-26 17:13:14

我必须复制并重命名文件,因此我收到有关创建文件或目录的提示。

这是我这样做的相当“hackish”的方式:

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

XCOPY 将使用“F”来指示它应该将目标创建为文件:

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 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 :-)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文