Como dizer não a todos os avisos de “você deseja substituir” em uma cópia de arquivo em lote?

StackOverflow https://stackoverflow.com/questions/191209

  •  08-07-2019
  •  | 
  •  

Pergunta

Por padrão, a cópia do prompt de comando solicitará que você substitua os arquivos que já existem no local de destino.

Você pode adicionar "/y" para dizer "sim a todos" substituições.

Mas como você pode dizer "não a todos"?

Em outras palavras, quero copiar tudo de um diretório que faz não já existe no alvo.

A coisa mais próxima que vejo é o argumento xcopy para copiar apenas as coisas após um modete de mod-DateTeT específico.

Foi útil?

Solução

A menos que haja um cenário em que você não Deseja copiar os arquivos existentes na fonte que mudaram desde a última cópia, por que não usar o Xcopy com /D sem especificar uma data?

Outras dicas

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

Você pode fazer um arquivo de texto com uma única linha longa de "n" e executar seu comando e colocar <nc.txt depois dele. Fiz isso para copiar mais de 145.000 instâncias em que "sem substituição" era o que eu queria e funcionou bem dessa maneira.

Ou você pode apenas segurar a tecla N com algo, mas isso leva mais tempo do que usar o <para tubá -lo.

Aqui está uma solução alternativa. Se você deseja copiar tudo de A que ainda não existe em B:

Copie A para um novo diretório C. Copie B para C, substituindo qualquer coisa que se sobreponda a A. Copiar C a B.

eu uso XCOPY Com os seguintes parâmetros para copiar os conjuntos .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.

Eu sei que todos vocês pensam /d: a data vai usar as coisas da data, mas apenas /D sem: faz exatamente o que queremos então ...

xcopy {Source} {Destination} /E /D 

Copiará sem sobrescrever para buscar os arquivos que são novos ou talvez falhados antes por algum motivo.

Apenas tente, funciona.

eu espero xxcopy tem um opção por isso.

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.

-Adão

Isso funciona bem

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

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

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)

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.

Depending on the size and number of files being copied, you could copy the destination directory over the source first with "yes to all", then do the original copy you were doing, also with "yes to all" set. That should give you the same results.

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.

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

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top