如何对批处理文件副本中的所有“你想要覆盖”提示说不?

时间:2008-10-10 13:16:36

标签: batch-file copy

默认情况下,从命令提示符复制将提示您覆盖目标位置中已存在的文件。

您可以添加“/ Y”来表示“是对所有人”替换。

但你怎么能说“不对所有人”?

换句话说,我想复制目标中已存在的目录中的所有内容。

我看到的最接近的是XCOPY参数,只能在特定的mod-datetime之后复制东西。

14 个答案:

答案 0 :(得分:70)

除非您的想要复制自上次复制以来已更改的源中的现有文件,否则为什么不在不指定日期的情况下将XCOPY与/ D一起使用?

答案 1 :(得分:28)

echo "No" | copy/-Y c:\source c:\Dest\

答案 2 :(得分:21)

您可以使用单个长行“n”创建一个文本文件,然后运行您的命令并将< nc.txt之后。我这样做是为了复制超过145,000个实例,其中“No overwrite”是我想要的,并且这样做很好。

或者你可以用一些东西按住n键,但这比使用<管道输入。

答案 3 :(得分:11)

这是一种解决方法。如果要复制B中尚未存在的所有内容:

将A复制到新目录C. 将B复制到C,覆盖与A重叠的任何内容。 将C复制到B。

答案 4 :(得分:6)

我使用XCOPY和以下参数来复制.NET程序集:

/D /Y /R /H 

/D:m-d-y - Copies files changed on or after the specified date. If no date is given, copies only those files whose source time is newer than the destination time.

/Y - Suppresses prompting to confirm you want to overwrite an existing destination file.

/R - Overwrites read-only files.

/H - Copies hidden and system files also.

答案 5 :(得分:6)

我知道你们都认为/ D:日期会使用日期的东西,但是只有/ D没有:确实是我们想要的......

xcopy {Source} {Destination} /E /D 

在没有覆盖的情况下进行复制,以便在出于某种原因之前拾取那些新的或可能失败的文件。

试试吧,它有效。

答案 6 :(得分:5)

我希望xxcopyoption

宾果:

http://www.xxcopy.com/xxcopy27.htm#tag_231

2.3   By comparison with the file in destination

    The switches in this group select files based on the
    comparison between the files in the source and those in
    the destination.  They are often used for periodic backup
    and directory synchronization purposes. These switches
    were originally created as variations of directory backup.
    They are also convenient for selecting files for deletion.

2.3.1  by Presence/Absence

    The /BB and /U switches are the two switches which select
    files by the pure presence or absence as the criteria.
    Other switches in the this group (Group 2.3) are also
    affected by the file in the destination, but for a
    particular characteristics for comparison's sake.

    /BB  Selects files that are present in source but not in destination.
    /U   Selects files that are present in both source and destination.

- 亚当

答案 7 :(得分:4)

这很好用

no | cp -rf c:\source c:\Dest\

答案 8 :(得分:4)

回音N | copy / -y $(SolutionDir)SomeDir $(OutDir)

答案 9 :(得分:3)

试试这个:

robocopy "source" "destination" /e /b /copyall /xo /it

将该行复制到记事本中并另存为.bat文件。运行该文件,它将复制从源到目标的所有内容。当您再次运行它时,它不会替换相同的文件。当您更改或文件更改时,它将替换目标文件。

测试一下。我创建了一个包含一些工作的.txt文件,运行脚本,更改.txt文件中的措辞并再次运行脚本,它只替换源中的更改文件。

/e=Copies subdirectories. Note that this option includes empty directories
/b=Copies files in Backup mode
/copyall=Copies all file information
/xo=Excludes older files. (this is what prevents it from copy the same file over and over)
/it=Includes "tweaked" files. (this will allow the copy and replace of modified files)

答案 10 :(得分:3)

谢谢你。我使用命令行实用程序AzCopy(v 3.1.0.93)将约100万个文件从我的本地PC移动到我的Azure blob存储。我有一些副本,不能照看副本来回答每个提示,并且不想重新上传同一个文件。

AzCopy实用程序提供了一个/ Y命令来抑制确认提示,但最终告诉它覆盖目标文件。走这条路线我能够让它不重新上传文件。然而,它确实看起来有点像黑客,因为它实际上并没有用" No"回答提示,而是我得到错误"当用户需要做出选择时没有收到任何输入几个给定的选项。"但不上传文件。

这是我使用的命令:echo n | AzCopy /来源:" {文件路径}" / Dest:" {blob storage URL}" / DestKey:{键}

希望这有助于下一个人。

答案 11 :(得分:2)

根据要复制的文件的大小和数量,您可以首先使用“yes to all”复制目标目录,然后执行您正在执行的原始副本,同时使用“yes to all”设置。这应该给你相同的结果。

答案 12 :(得分:0)

我们通过“invoke-command”使用“robocopy”来复制我们环境中的大量虚拟机。我们发现“robocopy”有时会意外地退出,整个过程都会消失。所以我们决定使用“xcopy”。现在我们正在检查它的工作并“创建”“Not for all”选项我们使用该功能(powershell):

function gen_long_no([string] $ path){     $ result =“”; Get-ChildItem $ path -Recurse | ? {if($ _.PSIsContainer -eq $ false){$ result + =“n”}};     返回$ result }

也许可以帮助别人。

答案 13 :(得分:0)

添加用于子目录和验证的开关就可以了。  回声n | xcopy / -Y / s / e / v c:\ source *。* c:\ Dest \