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

后端 未结 14 1226
感动是毒
感动是毒 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:51

    We used "robocopy" through "invoke-command" to copy a huge amount of VMs in our environment. We've discovered that "robocopy" unexpectedly exits sometimes and the whole proccess goes to down. So we've decided to use "xcopy". Now we're checking it's work and to "create" "Not for all" option we use that function (powershell):

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

    Maybe helps somebody.

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

    Adding the switches for subdirectories and verification work just fine. echo n | xcopy/-Y/s/e/v c:\source*.* c:\Dest\

    0 讨论(0)
  • 2020-12-23 12:02

    You can make a text file with a single long line of "n" then run your command and put < nc.txt after it. I did this to copy over 145,000 instances where "No overwrite" was what I wanted and it worked fine this way.

    Or you can just hold the n key down with something, but that takes longer than using the < to pipe it in.

    0 讨论(0)
  • 2020-12-23 12:03

    I know you all think /D: date is going to use date stuff, but just /D without the: does exactly what we want so...

    xcopy {Source} {Destination} /E /D 
    

    Will copy without overwriting to pickup those files that are new or maybe failed before for some reason.

    Just try it, it works.

    0 讨论(0)
  • 2020-12-23 12:06

    I use XCOPY with the following parameters for copying .NET assemblies:

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

    Thanks for this. I am using the command line utility AzCopy (v 3.1.0.93) to move ~1 million files from my local PC to my Azure blob storage. I've got some duplicates and cannot babysit the copy to answer each prompt and don't want to re-upload the same file.

    The AzCopy utility offers a /Y command to suppress the confirmation prompts but ends up telling it to overwrite the destination file. Going this route I was able to get it to NOT re-upload the file. However, it does seem like a bit of a hack since it is not actually answering the prompt with "No", instead I get the error "No input is received when user needed to make a choice among several given options." but does not upload the file.

    Here is the command I used: echo n | AzCopy /Source:"{file path}" /Dest:"{blob storage URL}" /DestKey:{key}

    Hope this helps the next guy.

    0 讨论(0)
提交回复
热议问题