How to say no to all “do you want to overwrite” prompts in a batch file copy?

后端 未结 14 1225
感动是毒
感动是毒 2020-12-23 11:36

By default, copying from the command prompt will prompt you to overwrite files that already exist in the target location.

You can add \"/Y\" to say \"Yes to all\" re

相关标签:
14条回答
  • 2020-12-23 11:42

    I expect xxcopy has an option for that.

    Bingo:

    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.
    

    -Adam

    0 讨论(0)
  • 2020-12-23 11:42

    Try this:

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

    Copy that line into notepad and save as a .bat file. Run the file and it will copy everything from the source to the destination. When you run it again it will not replace files that are identical. when you change or a file changes it will replace the file at the destination.

    test it out. I created a .txt file with a few works, ran the script, change the wording on the .txt file and ran the script again, it replace only the change file from the source.

    /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)
    
    0 讨论(0)
  • 2020-12-23 11:44

    Here's a workaround. If you want to copy everything from A that does not already exist in B:

    Copy A to a new directory C. Copy B to C, overwriting anything that overlaps with A. Copy C to B.

    0 讨论(0)
  • echo N | copy /-y $(SolutionDir)SomeDir $(OutDir)

    0 讨论(0)
  • 2020-12-23 11:49

    Unless there's a scenario where you'd not want to copy existing files in the source that have changed since the last copy, why not use XCOPY with /D without specifying a date?

    0 讨论(0)
  • 2020-12-23 11:49
    echo "No" | copy/-Y c:\source c:\Dest\
    
    0 讨论(0)
提交回复
热议问题