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

Jos*_*ons 54 copy batch-file

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

您可以添加"/ Y"来表示"是对所有人"替换.

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

换句话说,我要复制一切从一个目录,它不是已经在目标存在.

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

Kev*_*Kev 70

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


小智 29

echo "No" | copy/-Y c:\source c:\Dest\
Run Code Online (Sandbox Code Playgroud)

  • 令人惊奇的是,它适用于所有文件..您可以执行 echo n 而不是 echo "No"。回声| 复制/-Y *.txt df (2认同)
  • 实际上,你必须摆脱引号完全"复制兼容".IE如果用"是"代替"否",它仍然不会复制. (2认同)

小智 21

您可以使用单个长行"n"创建一个文本文件,然后运行您的命令并在其后面输入<nc.txt.我这样做是为了复制超过145,000个实例,其中"No overwrite"是我想要的,并且它以这种方式运行良好.

或者你可以用一些东西按住n键,但这需要比使用<管道输入更长的时间.

  • +1为lolfactor.还+1,因为这比利亚姆的解决方案更有效,有些人得到+3 ...... (10认同)

Lia*_*iam 11

这是一个解决方法.如果要复制B中尚不存在的A中的所有内容:

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


chi*_*tza 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.
Run Code Online (Sandbox Code Playgroud)


小智 6

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

xcopy {Source} {Destination} /E /D 
Run Code Online (Sandbox Code Playgroud)

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

试试吧,它有效.


Ada*_*vis 5

我希望xxcopy有一个选项.

答对了:

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.
Run Code Online (Sandbox Code Playgroud)

-亚当


gho*_*der 5

这工作正常

no | cp -rf c:\source c:\Dest\
Run Code Online (Sandbox Code Playgroud)

  • 也许我应该指定我使用的是 Windows。 (5认同)